Module level node is enough
Note that, when using the keyboard to check a Node, the message box should close by keyboard too otherwise the node remain checked!!!Code:Option Explicit Private mCheckedNode As MSComctlLib.Node Private Sub Form_Load() TreeView1.Nodes.Add , , , "1" TreeView1.Nodes.Add , , , "2" TreeView1.Nodes.Add , , , "3" TreeView1.Nodes.Add , , , "4" TreeView1.Nodes.Add , , , "5" End Sub Private Sub TreeView1_KeyUp(KeyCode As Integer, Shift As Integer) UndoNodeCheck End Sub Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) UndoNodeCheck End Sub Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node) If Node.Checked Then If MsgBox("Do you really want to check this node """ & Node.Text & """?", vbYesNo + vbDefaultButton2 + vbQuestion, "Confirm") = vbNo Then Set mCheckedNode = Node End If End If End Sub Private Sub UndoNodeCheck() If Not mCheckedNode Is Nothing Then mCheckedNode.Checked = False Set mCheckedNode = Nothing End If End Sub





Reply With Quote
