c# - how to replace TreeView's selected node with newly created node -
i have populated treeview node created, there several node classes, inherit treenode.
when edit node (using gui dialog), may alter different class, i'm creating new node in process, , trying replace selected node new node, doesn't work, node stays old one, cant figure out i'm doing wrong.
code:
treenodemission mission = (treenodemission)treeview.selectednode; treenodemission newmission = changemissiondialog(mission); treeview.selectednode = newmission; // doesn't work also tried removing , adding it, doesn't work
index = treeview.nodes.indexof(treeview.selectednode); // index returns -1 treeview.nodes.remove(treeview.selectednode); treeview.nodes.insert(index, newmission); what doing wrong?
update: treeview.selectednode not null, valid node selected.
solved it, found bug.
i found way replace node, removing , re-adding it. guess thought asking index give me general index in tree, gives index parent only, using parent node, can replace it:
int index = treeview.selectednode.index; treeview.selectednode.parent.nodes.removeat(index); treeview.selectednode.parent.nodes.insert(index, mission); treeview.selectednode = mission; thanks
c# winforms treeview
No comments:
Post a Comment