I am trying to port a VB6 application to .Net, and we must constantly provide like-like features. In one form, there is a tree structure with flags with three levels of nodes. The first level only serves to group the next level down, and they are not subject to verification. Second-level nodes are checked by the user, and when they are checked or not checked, all his children follow this example. At all levels, clicking on the node icon or its flag means that it will be selected, regardless of whether the validation state affects it.
The third level is the problemβs problem (although the problem itself appears in all treeview flags): this level contains two "types" of the node, one of which can be checked and not set by the user (if the parent is checked) and one type that cannot be checked or unchecked by the user regardless of the state of the parent, but its state mirrors its parent.
Under normal use, everything works as expected. However, if you quickly click one of the third-level nodes (which should not be directly checked) twice, it seems to change its check state. But if you study the basic value of the Checked property, it remains unaffected, so it seems like it's just a display problem. If found, this anomaly will be a problem for our customers, as users might think that they can do something that they cannot lead to expensive confusion.
I'm from fresh ideas about this - has anyone else observed this behavior or knew about it, and are there any workarounds / solutions? I can't help but feel that I missed something really obvious, but after a day and a half I now have a tunnel vision. Here is some code to demonstrate the problem. Create a form with a tree structure (large enough to see what happens) and two buttons, then leave it in:
Private _node As TreeNode = Nothing
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(_node.Text & " : " & _node.Checked.ToString)
_node = Nothing
End Sub
Private Sub InitialiseTreeview()
TreeView1.Nodes.Clear()
Dim ran As New Random
Randomize()
For i As Int32 = 1 To 5
Dim TLNode As New TreeNode
Dim children As Int32 = 0
children = ran.Next(1, 5)
TLNode.Text = "Top Level Node " & i.ToString
For j As Int32 = 1 To children
TLNode.Nodes.Add("Child Node " & j.ToString)
Next
TreeView1.Nodes.Add(TLNode)
Next
TreeView1.ExpandAll()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
InitialiseTreeview()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
InitialiseTreeview()
End Sub
Launch it and click node ONCE. Press button 1 and it will tell you the text node and check the status. Now double-click the same node, quickly, observe the state of the checkmark and press the 1 button again. You will understand what I mean. Button 2 creates a new set of tree nodes.