Issues with checbox in TreeViewAdv

Attached is my code.  When I click on a checkbox it will go to the alternate checkstate but then go back to the original.  If I double click the checkbox (I have no code in the 

TreeViewAdv2_NodeMouseDoubleClick it will stay at the correct checkstate.  If I put a breakpoint in my code or have something such as a msgbox command it will staty at the correct checkstate, however without any of these in place it will go back to the original checkstate.

What I want to accomplish if the users left clicks on the checkbox or the node text I want the node text to change (which it does correctly) but then alternate the checkstate from what it was (ie. if checked, then uncheck and vice-versa).  

It's a very strange issue.  I am running the latest controls.

Code:

Private Sub TreeViewAdv2_NodeMouseClick(sender As Object, e As TreeViewAdvMouseClickEventArgs) Handles TreeViewAdv2.NodeMouseClick

    ' Check for right-click to show Properties menu

    Dim selectedNode As TreeNodeAdv = e.Node

    If e.Mousebutton = MouseButtons.Right Then

        TreeViewAdv2.SelectedNode = selectedNode

        ' Display Properties menu based on node type

        If selectedNode.Parent IsNot Nothing AndAlso selectedNode.Parent.Text <> "root" AndAlso selectedNode.Parent.Text <> "Code" Then

            contextMenu.Items("Properties").Enabled = True

        Else

            contextMenu.Items("Properties").Enabled = False

        End If

        ' Show the context menu at the mouse position

        contextMenu.Show(MousePosition)

    Else

        'Dim selectedNode As TreeNodeAdv = e.Node

        Dim nodeInfo As tagData = TryCast(selectedNode.Tag, tagData)

        TreeViewAdv2.SelectedNode = selectedNode

        ' Update node text based on the intended checked state

        Try

            If Not selectedNode.Checked Then

                ' Node is being checked, update to newData

                If nodeInfo IsNot Nothing AndAlso Not String.IsNullOrEmpty(nodeInfo.newData) Then

                    selectedNode.Text = nodeInfo.newData

                End If

                selectedNode.CheckState = CheckState.Checked

            Else

                ' Node is being unchecked, revert to previousData

                If nodeInfo IsNot Nothing AndAlso Not String.IsNullOrEmpty(nodeInfo.previousData) Then

                    selectedNode.Text = nodeInfo.previousData

                End If

                selectedNode.CheckState = CheckState.Unchecked

            End If

        Catch ex As Exception

            LogError($"Error handling BeforeCheck state change: {ex.Message}")

        End Try


    End If

End Sub



6 Replies

MS Madhavan Sathapillai Syncfusion Team October 31, 2024 01:12 PM UTC

Hi Jeff,


We are currently analyzing your reported scenario. We need more time to validate the scenario, we will provide an update on or before November 04, 2024.



Regards,

Madhavan S



JE Jeff November 1, 2024 01:16 PM UTC

Were you able to look into this?



MA Manikanda Akash Munisamy Syncfusion Team November 4, 2024 02:42 PM UTC

Hi Jeff, 

We are currently preparing a workaround for your requirement. We still need more time to achieve this, and we will provide you further details by November 06, 2024.

Regards,
Manikanda Akash



MA Manikanda Akash Munisamy Syncfusion Team November 6, 2024 02:02 PM UTC

Hi Jeff,

We reviewed your requirement to modify both the CheckState and Node Text within the NodeMouseClick event. We understand that clicking directly on the checkbox currently changes only the Node Text while leaving the CheckState unchanged.

To resolve this, we implemented a flag within the NodeMouseClick event that detects if the click occurred specifically over the checkbox. When this happens, the flag prevents programmatic changes to the CheckState, allowing it to update as expected without interference. We have attached the prepared sample and video recording for your reference.

Code Snippet
Dim isMouseOverCheckBox = selectedNode.CheckBox.Bounds.Contains(TreeViewAdv1.PointToClient(Cursor.Position))
If Not selectedNode.Checked Then
   If nodeInfo IsNot Nothing AndAlso Not String.IsNullOrEmpty(nodeInfo.newData) Then
       selectedNode.Text = nodeInfo.newData
   End If
   If Not isMouseOverCheckBox Then
       selectedNode.CheckState = CheckState.Checked
   End If
Else
   If nodeInfo IsNot Nothing AndAlso Not String.IsNullOrEmpty(nodeInfo.previousData) Then
       selectedNode.Text = nodeInfo.previousData
   End If
   If Not isMouseOverCheckBox Then
       selectedNode.CheckState = CheckState.Unchecked
   End If
End If

This approach ensures:
  • Clicking directly on the checkbox only modifies the CheckState.
  • Clicking on the node text updates both the Node Text and CheckState.

If additional assistance is needed, please feel free to reach out. We’re here to help.

Regards,
Manikanda Akash


Attachment: TreeViewAdv_VB_55ceaad7.zip



JE Jeff November 7, 2024 01:16 PM UTC

Thank you!  Works great!



MA Manikanda Akash Munisamy Syncfusion Team November 8, 2024 07:01 AM UTC

Hi Jeff,


We're glad to hear that the approach we suggested worked well for you. Hence, we’ll be closing the forum.

Regards,
Manikanda Akash


Loader.
Up arrow icon