|
-
Oct 1st, 2001, 12:56 PM
#1
Thread Starter
Addicted Member
Freaky Treeview Checkbox Thing
I am trying to get the users confirmation when clicking a checkbox in the treeview control.
Code snippet:
Code:
Sub treeGuideline_NodeCheck(ByVal Node As MSComctlLib.Node)
If Node.Children > 0 Then 'Parent
msgreturn = MsgBox("Checking this node will select all sections and guidelines below it. Do you wish to continue?", vbYesNo + vbQuestion)
' If msgreturn = vbNo Then
' Node.Checke= False '***
' Else
' bDirty = True
'All the work done when checking/unchecking is done in the
'following 2 subs.
CheckNodes frmTree.treeGuideline, Node, Node.Checked, True
checkforsiblings frmTree.treeGuideline, Node, Node.Checked
' End If
End if
' some other stuff
End Sub
In debug mode, I can see the checkbox clear when the line *** is executed, but at the end of the sub, the check box rechecks itself. Nothing I do inside the sub, as far as checking/unchecking is persistent, when the sub ends, it sets the value to whatever was going to be when the user clicked. Is there any way to cancel a checkbox click?
Shawn Hull
VB6, SP3 (Professional Edition)
-
Oct 1st, 2001, 01:04 PM
#2
Re: Freaky Treeview Checkbox Thing
Originally posted by a2427
VB Code:
Sub treeGuideline_NodeCheck(ByVal Node As MSComctlLib.Node)
If Node.Children > 0 Then 'Parent
msgreturn = MsgBox("Checking this node will select all sections and guidelines below it. Do you wish to continue?", vbYesNo + vbQuestion)
' If msgreturn = vbNo Then
' Node.Checke= False '***
' Else
' bDirty = True
'All the work done when checking/unchecking is done in the
'following 2 subs.
CheckNodes frmTree.treeGuideline, Node, Node.Checked, True
checkforsiblings frmTree.treeGuideline, Node, Node.Checked
' End If
End if
' some other stuff
End Sub
Are you sure thats the code you want debugged? All your code lines are commented out except for 5 of them, including your *** line. Also, Typo alert :Node.Checke= False
-Lou
-
Oct 1st, 2001, 01:17 PM
#3
Thread Starter
Addicted Member
Try it again,
I had some temp stuff in there
Code:
Sub treeGuideline_NodeCheck(ByVal Node As MSComctlLib.Node)
Dim tnode As Node 'Node to pass
Dim msgreturn As Long
Dim chkflag As Boolean
Dim gid As String
If Node.Checked = True Then
If Node.Children > 0 Then 'Parent
msgreturn = MsgBox("Checking this node will select all sections and guidelines below it. Do you wish to continue?", vbYesNo + vbQuestion)
If msgreturn = vbNo Then
Node.Checked= False '***
Else
bDirty = True
'All the work done when checking/unchecking is done in the
'following 2 subs.
CheckNodes frmTree.treeGuideline, Node, Node.Checked, True
checkforsiblings frmTree.treeGuideline, Node, Node.Checked
End If
End If
End if
At least I know someone is paying attetion, any help?
Shawn Hull
VB6, SP3 (Professional Edition)
-
Oct 1st, 2001, 01:54 PM
#4
Fanatic Member
Hmmmmm......tried your code and it does what you say and I can't figure a way around it.
Has to be a bug.....I have VB 6 EE SP 3 as well.
-
Oct 1st, 2001, 02:15 PM
#5
Strange!
That check event Seems to freeze the treeview up to the point whare you can't change its check value.
But, I got something to work.
Put a timer control on your form, set its interval to 10, enabled = false.
Then, add the following code:
VB Code:
Private Sub Timer1_Timer()
treeGuideline.Nodes(Val(Timer1.Tag)).Checked = False
Timer1.Enabled = False
End Sub
And, finally alter your existing at the vbNo, to the following:
VB Code:
If msgreturn = vbNo Then
Timer1.Tag = Node.Index
Timer1.Enabled = True
Exit Sub
Else
Run it, and report back what happens. I hope it solves
your problem though.
-Lou
-
Oct 1st, 2001, 02:17 PM
#6
Also,
I have no idea what your two user defined subs do, but if
they also change the treeview check values, you might also have
to timer them, too.
-Lou
-
Oct 1st, 2001, 02:36 PM
#7
Thread Starter
Addicted Member
I had thoght about the timer but did not want to go there because of a user can start clicking other checkboxes before the first timer event is fired. I might have take that chance if there is no other way.
Thanks guys any other ideas.
Any other ideas.
Shawn Hull
VB6, SP3 (Professional Edition)
-
Oct 2nd, 2001, 08:54 PM
#8
Thread Starter
Addicted Member
I had to use the timer solution to this prroblem with a time of a about 10 th of second. It does not matter what you do inside the check event, the end result is the same. Also anything that breaks the event, hangs the sub- like launching a modal form. I am really beginning to dislike the treeview.
Shawn Hull
VB6, SP3 (Professional Edition)
-
Oct 3rd, 2001, 06:41 AM
#9
It sure is a pain!
Perhaps someone has made a custom Treeview? Or, perhaps you
could sub-class it? ie.., intercept its windows messages, and
respond when you get the Check message.
BTW, Like i previously mentioned, 10 works for me, that is
10/1000, or 1 oneHundreth of a sec. But, Just as long as its
under 1 sec, you should be good to go.
Now, you COULD make it invisible on a check event, and have the
timer turn it back, thus preventing users from checking before
your code is completed.
-Lou
-
Oct 3rd, 2001, 07:23 AM
#10
I admit I did not examine this thread in detail, but this may apply. There is a known bug when using the checkbox style with the treeview, and a workaround for it. Check out this thread and see if it applies:
http://www.vbforums.com/showthread.p...hreadid=100901
"It's cold gin time again ..."
Check out my website here.
-
Oct 3rd, 2001, 09:19 AM
#11
Thread Starter
Addicted Member
Thanks Lou, I had set the timer interval to 20 and it was definately fast enough. I kind of like the invisible idea. As far as subclassing, I am not at that at level but I get the concept.
Bruce,
I ran into that problem the first day with the treeview and actually used the code in that post to check my checkboxes and fix the bug.
This forum I has bailed me out several times on my current project.
Thanks all.
Shawn Hull
VB6, SP3 (Professional Edition)
-
Oct 12th, 2001, 03:46 AM
#12
Well ...
Originally posted by BruceG
I admit I did not examine this thread in detail, but this may apply. There is a known bug when using the checkbox style with the treeview, and a workaround for it. Check out this thread and see if it applies:
http://www.vbforums.com/showthread.p...hreadid=100901
Bruce, that article only talks about the Node_Click event. I still have a problem here.
I want to implement a functionality where I shall verify the node checked and if a certain condition is false, I need to uncheck that node.
I have a treeview, and using the API calls provided in this article, I set its Checkboxes property, the .Checkboxes property is set to False. I write the following code in my form:
VB Code:
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Sub Form_Load()
Const TVS_CHECKBOXES = &H100
Const GWL_STYLE = (-16)
Dim CurStyle As Long
Dim Result As Long
Dim nodX As Node
Set nodX = TreeView1.Nodes.Add(, , "R", "Root")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C1", "Child 1")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C2", "Child 2")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C3", "Child 3")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C4", "Child 4")
nodX.EnsureVisible
TreeView1.LabelEdit = tvwManual
TreeView1.Style = tvwTreelinesText ' Style 4.
TreeView1.BorderStyle = vbFixedSingle
CurStyle = GetWindowLong(TreeView1.hwnd, GWL_STYLE)
Result = SetWindowLong(TreeView1.hwnd, GWL_STYLE, _
CurStyle Or TVS_CHECKBOXES)
End Sub
Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
If Node.Text = "Child 2" Then
Node.Checked = False
End If
End Sub
Now, if I set .Checkboxes property of the treeview control to False, the Node_Check event is never fired. And if I set the .Checkboxes property to True, the event is duly fired, and after Node.Checked = False, the node is unchecked, but when the procedure exits, the node has been checked back. This is a behaviour not addressed by the article you mentioned. And I think that's exactly the problem reported in this thread. Since I am facing a similar problem, I am curious to know the solution.
.
-
Oct 12th, 2001, 08:43 AM
#13
Got It!
The key is the mouse_up event occurs After the node_check event.
Heres some code to illustrate how its done:
VB Code:
Dim let_me_check As Boolean
Dim mouse_down As Boolean
Dim C_NODE As Node
Private Sub Form_Load()
Dim nodX As Node ' Declare the object variable.
Dim NodY As Node
Dim I As Integer ' Declare a counter variable.
For I = 1 To 4
Set nodX = TreeView1.Nodes.Add(, , , "Node " & CStr(I))
For J = 1 To 4
Set NodY = TreeView1.Nodes.Add(nodX, tvwChild, , "Node " & I & J)
Next J
Next I
End Sub
'it doesn't seem needed, but as a looping safety precaution
'the mouse_down boolean signifies that, if a node_check occured
'while mouse_down is true, it occured from the user physically
'checking it.
'ie.. if you uncheck or check it programically, You won't start looping
'if you use it correctly
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
mouse_down = True
End Sub
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
'of course, mouse_up occurs after mouse_down, so we dont need to check the mouse_down bool
'but, still reset it to false
mouse_down = False
'if a node was checked, then let_me_check indicates you need to inspect the node value
'against your conditions. Just for testing,
'Im checking the passed node value against the check controls check value.
'In this routine, it allows un-checking when Check1 = 1,
'but not checking when check1.Value = 1
If let_me_check = True Then 'place your inspection routine inside this if...endif
If (Check1.Value = 1) And (C_NODE.Checked = True) Then
C_NODE.Checked = False
End If
let_me_check = False
End If
End Sub
Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
'if the check occured from a mouse_down event, then do a setup
'on the variables needed for your inspection routine.
If mouse_down = True Then
Set C_NODE = Node
let_me_check = True
End If
End Sub
and I attached my development project.
-Hope this helps
-Lou
-
Oct 12th, 2001, 08:48 AM
#14
??????????????
honeybee = a2427?
Or, are you just in similar straits?
-Lou
-
Oct 13th, 2001, 04:56 AM
#15
Well ...
No, I am posting under just the name 'honeybee'. I don't wanna post under a different name and divide up the posts between them. I want to get to 4096 fast!!
I guess I have been dumb enough not to have thought of MouseUp. Thanks for bringing it up, I shall give it a thought.
.
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
|