how to get the index of current selected node from treeview in c# -
i'm working on form application in c# includes treeview in it. want attach panel each node whenever user clicks on node panel updated according node selected.
problem i'm facing when select node, application nothing when select node application shows content related selected node. means app getting content related last selected node not current one. example if i'll select "text" node, label show nothing , after if i'll select other node "appearance" label show "text" last selected node.
following here image of form contains treeview.
testing purpose i'm storing selected node's value in label's text here's code.
public partial class texteditor_preferences : form { public texteditor_preferences() { initializecomponent(); } list<panel> mypanels = new list<panel>(); //ignore line of code ! private void sidebar_mouseclick(object sender, mouseeventargs e) { label1.text = sidebar.selectednode.tostring(); } }
can anobody suggest me method?
if i'm missing or question not valid, please let me know explicitly. thanks
treeview control has afterselect event should write code in handler.
public yourform() { initializecomponent(); treeview.afterselect += treeviewafterselect; } private void treeviewafterselect(object sender, treevieweventargs e) { string nodetext = treeview.selectednode.text; // update panel here accordingly }
Comments
Post a Comment