logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
ophthalmos Posted: Sunday, May 9, 2021 11:48:41 AM(UTC)
 
Nice code! Learned something again!
Paul Rayman Posted: Sunday, May 9, 2021 12:04:29 AM(UTC)
 
In this case, one unnecessary search is performed in the collection of root elements.
Here is another option :)
Code:
if((currBookmark.Parent?.Childs ?? pdfViewer1.Document.Bookmarks).Remove(currBookmark))
ophthalmos Posted: Saturday, May 8, 2021 10:14:36 PM(UTC)
 
Many Thanks! Thats how it works:

Code:
if (pdfViewer.Document.Bookmarks.Remove(currBookmark) || currBookmark.Parent.Childs.Remove(currBookmark))
Paul Rayman Posted: Saturday, May 8, 2021 7:03:28 PM(UTC)
 
Bookmarks are grouped into a tree. And you are trying to remove a bookmark from the flat list that is the root of this tree. Instead, you must remove the bookmark from the flat list of children of the parent of the bookmark. Something like that:
Code:
currBookmark.Parent.Childs.Remove(currBookmark);
ophthalmos Posted: Saturday, May 8, 2021 1:27:53 PM(UTC)
 
Code:
private PdfBookmark currBookmark = null;

private void TraverseBookmark(PdfBookmarkCollections bookmarks, int iLevel, string nTitle)
{
    foreach (PdfBookmark item in bookmarks)
    {
        TraverseBookmark(item.Childs, iLevel + 1, nTitle);
        if (item.Title.Equals(nTitle)) { currBookmark = item; }
    }
}

private void DeleteThisBookmarkToolStripMenuItem_Click(object sender, EventArgs e)
{
    currBookmark = null;
    TraverseBookmark(pdfViewer.Document.Bookmarks, 0, bookmarksViewer.SelectedNode.Text);
    if (currBookmark != null)
    { //MessageBox.Show(currBookmark.Title);
        if (pdfViewer.Document.Bookmarks.Remove(currBookmark))
        {
            bookmarksViewer.RebuildTree();
            bookmarksViewer.ExpandAll();
        }
        else { Console.Beep(); }
    }
}


The PdfBookmarkCollections.Remove Method doesn't delete any element which is a child element!?