Compartilhar via


Code for the table sorting powertoy for OneNote 2010

Way back when Nani wrote the Table of Contents for OneNote 2007, I looked at her code. She used a DataGridView control to help create the table of contents. This is a nice control to have available and she had this line in the original code:

 

dgvPageList.Sort(dgvPageList.Columns[2], ListSortDirection.Descending);

 

Notice that Sort method? It is included with the DataGridView:

Sort(DataGridViewColumn, ListSortDirection) and here is the MSDN definition:

Sorts the contents of the DataGridView control in ascending or descending order based on the contents of the specified column.

 

Pasted from <https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.aspx>

(See, I use OneNote to write these blog entries. I'm leaving in the URL location text here just to help make that point).

 

That control has a TON of properties, methods and events built into it. The documentation for it is complete and there are many samples and code snippets that go with it. The sort method is buried in there and I'm happy someone managed to find and use it.

 

Anyway, we talked about this a little and realized that once the data from any table was put into this control, it could be sorted. From there, it got put on the back burner while we worked on OneNote 2010. Now that we are done, Nani took another look at the control and finished this powertoy. I know this has been requested and it's nice to see a solution available.

 

As mentioned last week, I'm including the code here. Thanks Nani! It is included in the link below my signature below. If you extend this, localize it for another language or anything else, please let me know. I'd love to go ahead and post any updates anyone makes, or just link to what you do to make this even better.

 

Questions, comments, concerns and criticisms always welcome,

John

TOC Power Toy 2010 - Sources.zip

Comments

  • Anonymous
    November 04, 2010
    The comment has been removed

  • Anonymous
    November 04, 2010
    The comment has been removed

  • Anonymous
    December 16, 2010
    John, thanks so much for sharing this code! I have just been able to get a sample addon working in the Ribbon interface after wanting to do so since OneNote 2010 was in beta. Thank you very much, and thank you to Nani for the code.

  • Anonymous
    January 18, 2011
    What is the license for this code? Can we redistribute parts of the source (non-commercial, with attribution), for example, on our blog?

  • Anonymous
    January 24, 2011
    Blog away!

  • Anonymous
    April 20, 2011
    I have modified the source code to create a TOC for an entire Notebook. Can I freely redistribute my changes to the community?

  • Anonymous
    April 20, 2011
    Hi Brad - absolutely.  You can let me know and I can post it here, or you can blog this yourself, etc...  If you need it, I can dig up the license agreement from msdn.com, though.  

  • Anonymous
    October 04, 2013
    John I am fairly new to using one note but love, love love it... i am trying to get tables i build inside onenote to be sortable...is this what i need here in this blog?

  • Anonymous
    October 04, 2013
    Hello Teresa - what version of OneNote do you have?

  • Anonymous
    October 04, 2013
    i have the 32bit version. i have added the table of contents add in but i want to sort tables that i have inserted into onenote, is that possible in 2010 with an add in?

  • Anonymous
    October 04, 2013
    Yes - it is available here: blogs.msdn.com/.../table-sorting-and-table-of-contents-powertoy-for-onenote-2010.aspx Just happens to be the previous blog entry to this one. Also, this functionality is built into OneNote 2013, so if you upgrade, you won't need this any longer.