|
-
Feb 1st, 2018, 08:00 AM
#1
Thread Starter
Fanatic Member
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
Last edited by mutley; Feb 1st, 2018 at 08:34 AM.
-
Feb 2nd, 2018, 06:01 AM
#2
Thread Starter
Fanatic Member
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
-
Feb 2nd, 2018, 06:34 AM
#3
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 2nd, 2018, 06:39 AM
#4
Thread Starter
Fanatic Member
Re: Check and Uncheck treeview when ask for user
Thank you
But when I put
Code:
node.CHECKED = False
The checkbox stiil marked
-
Feb 2nd, 2018, 07:34 AM
#5
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 2nd, 2018, 03:57 PM
#6
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 2nd, 2018, 05:43 PM
#7
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!!!
-
Feb 2nd, 2018, 09:48 PM
#8
Re: Check and Uncheck treeview when ask for user
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 2nd, 2018, 10:53 PM
#9
Re: Check and Uncheck treeview when ask for user
 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.
-
Feb 3rd, 2018, 01:43 AM
#10
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|