I am currently working on a wpf project in C#.
I have a treeview created that has parent nodes with childen nodes inside of it.
I was wondering if there was a way to get the index of the child node the user clicked on. (Simmilar to ".SelectedIndex" when using comboboxes)
I have tried Various ways such as:
int val =TreeView.SelectedItemProperty.GlobalIndex;
and
fileInput.IndexOf(treeView1.SelectedItem);
But they dont seem to work.
Any suggestions or comments are greatly appreciated.
Thanks
This post discusses exactly what you need I think. About handling the
SelectedNodeChanged
event and also a custom piece of code for an event that fires when the currently selected node is clicked...because then theSelectedNodeChanged
doesn't fire (the selected node doesn't change actually). Good luck!may you have to loop over tree nodes to get the index of
SelectedItem
. you can do that usingOnItemSelected
event.for ex.