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 <http://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 (11)

  1. GM says:

    Thanks, great addition.

    John, those "Pasted from" lines are great, but is it possible a) to not have the extra blank line between the pasted text and the caption and b) revert to the Normal style at the end of the text?

  2. JohnGuin says:

    We're contemplating a change for the style changing.  I'll pass along the blank line feedback.  FWIW, I like having the blank line to give me a place to click and type under the image.

  3. M.Ahrens says:

    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.

  4. M.Ahrens says:

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

  5. JohnGuin says:

    Blog away!

  6. Brad says:

    I have modified the source code to create a TOC for an entire Notebook. Can I freely redistribute my changes to the community?

  7. JohnGuin says:

    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.  

  8. Teresa says:

    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?

  9. JohnGuin says:

    Hello Teresa – what version of OneNote do you have?

  10. Teresa says:

    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?

  11. John says:

    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.