Check and Uncheck treeview when ask for user
Hi
I have a treeview with checkbox , Ordered me when the user click in Checkbox of the treeview I must to ask if the user want really to check , if Answer equal yes keep checked , but if the user responds NO , I must uncheck
How can I to it ?
I tried something like
Code:
Private Sub tvLista_NodeCheck(ByVal node As MSComctlLib.node)
Dim mIndAtiva As String
Dim strSQL As String
Dim Ds As Object
Dim mnode As node
Dim msgNode As String
On Error GoTo ErrorHandler
'----ask to user
if anwwer is NO
node.CHECKED = False
But no worked
Tia
1 Attachment(s)
Re: Check and Uncheck treeview when ask for user
Hi
Sorry for the insistence
but does anyone know how to solve this?
when the user responds NO to a question when clicking on the checkbox he can not check the treeview checkbox
https://s18.postimg.org/njx8a3lsp/pergunta.jpg
Attachment 155893
Re: Check and Uncheck treeview when ask for user
see if this will do what you want
Code:
'----ask to user
If MsgBox("Do you really want to check the box?", vbYesNo, "Are you sure") = vbNo Then
node.CHECKED = False
end if
Re: Check and Uncheck treeview when ask for user
Thank you
But when I put
Code:
node.CHECKED = False
The checkbox stiil marked
Re: Check and Uncheck treeview when ask for user
Code:
Dim n As Node, c As Boolean
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If c Then n.Checked = False: c = False
End Sub
Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
If Node.Checked Then
If MsgBox("Do you really want to check the box?", vbYesNo, "Are you sure") = vbNo Then
c = True
Set n = Node
End If
End If
End Sub
i tested this it seemed to work as requested, but only if the checkbox is changed by the mouse
if you need to trap if the user uses the keyboard to check the box, i think you will have to use some sort of a timer, or force a lostfocus event
Re: Check and Uncheck treeview when ask for user
i tested with a timer, worked correctly, however the checkbox was checked
Code:
Dim n As Node, c As Boolean
Private Sub Timer1_Timer()
If c Then
n.Checked = False
c = False
Timer1.Enabled = False
End If
End Sub
Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
If Node.Checked Then
If MsgBox("Do you really want to check the box?", vbYesNo, "Are you sure") = vbNo Then
c = True
Set n = Node
Timer1.Enabled = True
End If
End If
End Sub
i just had the timer interval of 1 and enabled = false
Re: Check and Uncheck treeview when ask for user
Module level node is enough
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
Note that, when using the keyboard to check a Node, the message box should close by keyboard too otherwise the node remain checked!!!
Re: Check and Uncheck treeview when ask for user
Quote:
Note that, when using the keyboard to check a Node, the message box should close by keyboard too otherwise the node remain checked!!!
yes, i was not real keen to use a timer, but i could not get the key up to be reliable, as i often closed the msgbox by mouse
Re: Check and Uncheck treeview when ask for user
Quote:
Originally Posted by
westconn1
yes, i was not real keen to use a timer, but i could not get the key up to be reliable, as i often closed the msgbox by mouse
Sorry, i missed your comment about this issue.
Re: Check and Uncheck treeview when ask for user
Yes, you can't change .Checked within the NodeCheck event handler. I tried this with success:
Code:
Private Sub tmrDefer_Timer()
With tmrDefer
.Enabled = False
TreeView1.Nodes(CInt(.Tag)).Checked = False
End With
End Sub
Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
With Node
If .Checked Then
If MsgBox("Do you really want to check:" _
& vbNewLine & vbNewLine _
& """" & .FullPath & """", vbOKOnly Or vbYesNo) = vbNo Then
tmrDefer.Tag = CStr(.Index)
tmrDefer.Enabled = True
End If
End If
End With
End Sub