Click here to Skip to main content
15,937,735 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I have a treeview and a listbox. For each node, there are some related items in the listbox. I want when the selected node in treeview changes, the items selected in the listbox change too based on the selected treeview node. How can I do that? Briefly, I want that the collection of the selected items in the listbox change in runtime.
I used a code like this:
foreach (DataRowView i in listBox_WorkOverOperationWhichinHole.Items)

but I do not know what to do next is it a true way to do that!

Thanks a lot in advance!

1 solution

Handle the tree view's AfterSelect[^] event to be notified when the selection in the tree view changes. The SelectedNode[^] property tells you what's selected. Note that the event doesn't fire for de-selects.

The ListBox[^] has a ton of ways to get/set the selected items. Look at all of the properties that begin with the word Selected and the SetSelected method.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900