|
|
Nice code! Learned something again!
|
|
|
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))
|
|
|
Many Thanks! Thats how it works: Code:if (pdfViewer.Document.Bookmarks.Remove(currBookmark) || currBookmark.Parent.Childs.Remove(currBookmark))
|
|
|
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);
|
|
|
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!?
|
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close