Search code examples
c#ms-wordbookmarks

Ordering bookmarks c#


i have a template word file with 4 different bookmarks, i want to add them to the form.

foreach (Bookmark bookmark in WordDocument.Bookmarks)
{
    dataGridView1.Rows.Add(bookmark.Name);                  
 }

But in the grid they are ordered by name, though i want them ordered by location, ive tried this construction:

var orderedBoomarks = WordDocument.Bookmarks.Cast<Bookmark>()
                          .OrderBy(d => d.Start).ToList();

How can i use this variable and insert it to my grid?(I barely understand what means this construction). Thanks!!


Solution

  • var orderedBoomarks = WordDocument.Bookmarks.Cast<Bookmark>().OrderBy(d => d.Start);
    foreach (var bookmark in orderedBoomarks)
        dataGridView1.Rows.Add(bookmark.Name);