This example adds three Node objects to a TreeView control. When you attempt to edit a Node object's label, the object's index is checked. If it is 1, the operation is canceled. To try the example, place a TreeView control on a form and paste the code into the form's Declarations section. Run the example, click twice on the top Node object's label to edit it, type in some text, and press ENTER.
Private Sub Form_Load()
TreeView1.Style = tvwTreelinesText ' Lines and text.
Dim nodX As Node
Set nodX = TreeView1.Nodes.Add(,,,"Parent")
Set nodX = TreeView1.Nodes.Add(1,tvwChild,,"Child1")
Set nodX = TreeView1.Nodes.Add(1,tvwChild,,"Child2")
nodX.EnsureVisible ' Make sure all nodes are visible.
End Sub
Private Sub TreeView1_AfterLabelEdit _
(Cancel As Integer, NewString As String)
' If current node's index is 1, edit is canceled.
If TreeView1.SelectedItem.Index = 1 Then
Cancel = True
MsgBox "Can't replace " & TreeView1.SelectedItem.Text & _
" with " & NewString
End If
End Sub
This example adds three ListItem objects to a ListView control. When you attempt to edit a ListItem object's label, the object's index is checked. If it is 1, the operation is canceled. To try the example, place a ListView control on a form and paste the code into the form's Declarations section. Run the example, click twice on any ListItem object's label to edit it, type in some text, and press ENTER.
Private Sub Form_Load()
Dim itmX As ListItem
Set itmX = ListView1.ListItems.Add(,,"Item1")
Set itmX = ListView1.ListItems.Add(,,"Item 2")
Set itmX = ListView1.ListItems.Add(,,"Item 3")
End Sub
Private Sub ListView1_AfterLabelEdit _
(Cancel As Integer, NewString As String)
' If current ListItem's index is 1, edit is canceled.
If ListView1.SelectedItem.Index = 1 Then
Cancel = True
MsgBox "Can't replace " & ListView1.SelectedItem.Text & _
" with " & NewString
End If
End Sub