Hello Stackoverflow Contributors,
I have a Combo Box "CmboExpenseType" with no data in at the moment.
I also have a Tree View "TVProperties" with the following data.
I'd like to get the Parent Nodes from this tree view into the "CmboExpenseType".
So when the user clicks on the Combo Box they will see the parent nodes "Income, Entertainment, Transportation & Others" and then I can program the Child Nodes to go into another Combo Box.
I'm not trying to get a Combo Box into my Tree View.
I have only tried this code at this time. But it worked to no avail.
CmboExpenseType.Items.Add(TVProperties);
Would it be worth me moving the nodes into a list or dictionary?
I have some ideas on possible ways after of getting all Parent Nodes in, like a possible foreach loop. I'm just stuck on adding the data from the Tree View into my Combo Box.
Any help would be fantastic. If more information is need please don't hesitate to tell me.
As you've probably discovered, there's no databinding for a treeview so they can't share a datasource.
To get the treeview to change when the combo changes, we can use a little databinding magic:
Then on the selected value change of the combo, just pull out the selected value:
If you want to take the node text from existing TreeView, you can do the following
Not sure about how you populate the
TreeView
in first place, It will be easy to populate theComboBox
at the same time with only first level node data.