Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
How to detect a click on a specific image on a node
posted

Hi,

I am able to differentiate between a click on an image and the text portion of a node in an UltraTree by doing the following (after a few checks before):

VB code:

If tree.UIElement.LastElementEntered.GetAncestor(GetType(Infragistics.Win.UltraWinTree.NodeTextUIElement)) IsNot Nothing Then

  ' Clicked on the text portion

ElseIf tree.UIElement.LastElementEntered.GetAncestor(GetType(Infragistics.Win.ImageUIElement)) IsNot Nothing Then

  ' Clicked on the image portion

End If

Now, I have two images on my node, I don't care if it is two Left Images or one Left Image and one Node Appearance Image and I want to be able to detect which image is the one that was clicked.

How can I go about that?

I tried to use your Infragistics UIElementViewer Utility, but it does not work with Infragistics v.14.1 (also, your download link is not working)

Thanks for your help.

Parents
No Data
Reply
  • 6158
    Verified Answer
    Offline posted

    Hello.

    The images in the LeftImages/RightImages collection were not intended to be used as buttons, so there is no particular built event for this scenario. Your approach of utilizing the ImageUIElement should work. However, you will most likely have to perform object comparisons on the clicked image to the images in the collections. Try some code like the following:

    Private Sub UltraTree1_MouseClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles UltraTree1.MouseClick

    Dim element As UIElement = Me.UltraTree1.UIElement.ElementFromPoint(e.Location)

    If element Is Nothing Then

    Return

    End If

    If element.GetType() Is GetType(ImageUIElement) Then

    Dim clickedImage As Image = CType(element, ImageUIElement).Image

    Dim node As UltraTreeNode = element.GetContext(GetType(UltraTreeNode))

    If node Is Nothing Then

    Return

    End If

    For i As Integer = 0 To node.LeftImages.Count - 1

    If Object.Equals(node.LeftImages(i), clickedImage) Then

    MessageBox.Show(String.Format("Left Image {0} clicked!", i))

    Return

    End If

    Next

    For i As Integer = 0 To node.RightImages.Count - 1

    If Object.Equals(node.RightImages(i), clickedImage) Then

    MessageBox.Show(String.Format("Right Image {0} clicked!", i))

    Return

    End If

    Next

    End If

    End Sub

    Let me know if you have any questions.

    Chris

Children