Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi selection in treeview

Status
Not open for further replies.

PankajAgr

Technical User
Jul 30, 2003
52
IN
Hi Guys,

Is there any way to select the multiple node in treeview control?

Thanks in advance.

Regds,
Pankaj


Senior Software Engineer,
Infotech Enterprises Limited
Hyderabad, Andhra Pradesh, India.
URL :
 
not as far as i know without sub classing the control

Jamie Gillespie
j-gillespie@s-cheshire.ac.uk
 
If not then is there any other solution for this problem.

Senior Software Engineer,
Infotech Enterprises Limited
Hyderabad, Andhra Pradesh, India.
URL :
 
could you explain more fully what it is you are trying to achieve?

Jamie Gillespie
j-gillespie@s-cheshire.ac.uk
 
I would also like to know the answer to this question. I would like to select multiple items in a treeview control without using checkboxes. The same functionality is available by using the multiselect property on a list box.

I.E.: objListBox.MultiSelect = Extended

Any help would be appreciated -- PankajAgr, did you ever find a solution to this?

-Ashley
 
Hi Ashley,

There is no properties is available for multi selection in tree view. But I write a small routine for multi selection in tree view. This functionality works same as window functionality like multi select through <Shift> & <Ctrl> key. Hopes it solves your problem-
Just copy this code in your application & run it-


Dim blnMultiselectedOn As Boolean
Dim blnMultiNodeSelected As Boolean
Dim intLastSelectedNodeID As Integer
Dim strSelectedParentKey As String


Private Sub Form_Initialize()
blnMultiselectedOn = False
blnMultiNodeSelected = True
intLastSelectedNodeID = 0
End Sub

Private Sub TreeView1_Click()
strOldSelectedKey = strSelectedParentKey
If TreeView1.SelectedItem.Index > 1 Then
strSelectedParentKey = TreeView1.SelectedItem.Parent.Key
Else
strSelectedParentKey = ""
End If
If blnMultiNodeSelected = True Or (strOldSelectedKey <> strSelectedParentKey And strOldSelectedKey <> "") Then
For I = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(I).BackColor = &HFFFFFF
TreeView1.Nodes(I).ForeColor = &H0&
Next
blnMultiNodeSelected = False
End If
strOldSelectedKey = TreeView1.SelectedItem.Key
End Sub
Private Sub TreeView1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim intCount As Integer
If blnMultiselectedOn = False Then
strSelectedParentKey = ""
strLastSelectedParentKey = ""
intLastSelectedNodeID = 0
End If

If KeyCode = 16 And intLastSelectedNodeID > 0 And intLastSelectedNodeID <> TreeView1.SelectedItem.Index And blnMultiselectedOn = True Then
If TreeView1.SelectedItem.Parent.Key <> TreeView1.Nodes(intLastSelectedNodeID).Parent.Key Then
TreeView1.Nodes(intLastSelectedNodeID).BackColor = &HFFFFFF
TreeView1.Nodes(intLastSelectedNodeID).ForeColor = &H0&
End If
If (intLastSelectedNodeID + 1) <= TreeView1.SelectedItem.Index - 1 Then
For intCount = intLastSelectedNodeID + 1 To TreeView1.SelectedItem.Index - 1
If TreeView1.SelectedItem.Parent.Key = TreeView1.Nodes(intCount).Parent.Key Then
TreeView1.Nodes(intCount).BackColor = &H8000000D
TreeView1.Nodes(intCount).ForeColor = &H80000009
End If
Next
Else
If (intLastSelectedNodeID + 1) >= TreeView1.SelectedItem.Index - 1 Then
For intCount = TreeView1.SelectedItem.Index - 1 To intLastSelectedNodeID + 1 Step -1
If TreeView1.SelectedItem.Parent.Key = TreeView1.Nodes(intCount).Parent.Key Then
TreeView1.Nodes(intCount).BackColor = &H8000000D
TreeView1.Nodes(intCount).ForeColor = &H80000009
End If
Next
End If
End If
End If
If KeyCode = 17 Or KeyCode = 16 Then
blnMultiselectedOn = True
End If
If blnMultiselectedOn = True Then
TreeView1.SelectedItem.BackColor = &H8000000D
TreeView1.SelectedItem.ForeColor = &H80000009
intLastSelectedNodeID = TreeView1.SelectedItem.Index
End If
End Sub
Private Sub TreeView1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 17 Or KeyCode = 16 Then
blnMultiselectedOn = False
blnMultiNodeSelected = True
intLastSelectedNodeID = 0
End If
End Sub

Thanks
Pankaj

Senior Software Engineer,
Infotech Enterprises Limited
Hyderabad, Andhra Pradesh, India.
URL :
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top