0

i want to select multiple node for a treeview using shiftkey as shown in below image

Treeview with selection multiple node using shift

how to get the first clicked node index and then next clicked with shift key node index.

i have tried with below code snippet

 Dim firstSelectedChildIndex As Integer = treeview1.selectedNode.Index
 Dim lastSelectedChildIndex As Integer = treeview1.selectedNode.Index
 Dim parentNodeIndex As Integer = treeview1.selectedNode.Parent.Index


 Do      

 tvwAttributes.Nodes(parentNodeIndex).Nodes.Item(firstSelectedChildIndex).BackColor = Color.DodgerBlue

 tvwAttributes.Nodes(parentNodeIndex).Nodes.Item(firstSelectedChildIndex).BackColor = Color.White
 firstSelectedChildIndex += 1

 Loop Until firstSelectedChildIndex = lastSelectedChildIndex 

can i have any sample code or any clue how to do this?

Thanks in advance!!!!!

Hrqls
  • 2,944
  • 4
  • 34
  • 54
Piyush
  • 5,145
  • 16
  • 49
  • 71
  • Please focus on a single language. Tagging multiple languages usually results in downvotes and people confused as to how to contribute. – crthompson Apr 29 '14 at 16:30
  • 1
    TreeView does not support multiple selections. You'll have to add a lot of plumbing to simulate it. Starting with a collection object that can store the selection range. Lots of logic to avoid selecting across different levels. Custom drawing to colorize the background. Node selection with the NodeClick event is certainly the smaller problem. But of course you cannot implement it until you put the plumbing in place first. – Hans Passant Apr 29 '14 at 17:03
  • possible duplicate of [Multiple selection in a TreeView](http://stackoverflow.com/questions/1665597/multiple-selection-in-a-treeview) and [How do I allow multi-select in a .NET TreeView?](http://stackoverflow.com/q/206096) – Cody Gray - on strike Apr 30 '14 at 06:46

2 Answers2

1

In VB.Net, TreeView has a CheckBoxes property, that creates a checkbox next to each node. You can use this for multiple select, but not Shift + Click I'm afraid.

Piratica
  • 483
  • 2
  • 11
1

Here is an article on how to do this.

Derive from base TreeView and enable multiple selection by overriding specific behaviors

Piyush
  • 5,145
  • 16
  • 49
  • 71