This example adds several Node objects to a TreeView control. If you try to edit a label, the Node object's index is checked. If it is 1, the edit is prevented. To try the example, place a TreeView control on a form and paste the code into the form's Declarations section. Run the example, and try to edit the labels.
Private Sub Form_Load()
Dim nodX As Node
Set nodX = TreeView1.Nodes.Add(,,"P1","Parent 1")
Set nodX = TreeView1.Nodes.Add("P1",tvwChild,,"Child 1")
Set nodX = TreeView1.Nodes.Add("P1",tvwChild,,"Child 2")
nodX.EnsureVisible ' Make sure all nodes are visible.
End Sub
Private Sub TreeView1_BeforeLabelEdit(Cancel As Integer)
' Check selected node's index. If it is 1,
' then cancel the editing operation.
If TreeView1.SelectedItem.Index = 1 Then
MsgBox "Can't edit " + TreeView1.SelectedItem.Text
Cancel = True
End If
End Sub
This example adds several ListItem objects to a ListView control. If you try to edit a label, the ListItem object's index is checked. If it is 1, the edit is prevented. To try the example, place a ListView control on a form and paste the code into the form's Declarations section. Run the example, and try to edit the labels.
Private Sub Form_Load()
Dim nodX As ListViewItem
Set nodX = ListView1.ListItems.Add(, , "Item 1")
Set nodX = ListView1.ListItems.Add(, , "Item 2")
Set nodX = ListView1.ListItems.Add(, , "Item 3")
End Sub
Private Sub ListView1_BeforeLabelEdit(Cancel As Integer)
' Check selected item's index. If it is 1,
' then cancel the editing operation.
If ListView1.SelectedItem.Index = 1 Then
MsgBox "Can't edit " + ListView1.SelectedItem.Text
Cancel = True
End If
End Sub