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.
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
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
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))
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))
End Sub
Let me know if you have any questions.
Chris
Hi Chris,
thanks for the tip.
Unfortunately, the Object.Equals doesn't work on Images, so I created my own Comparer (pixel by pixel)
And it now works perfectly.
It might be a good idea to include the ability to tell which image is clicked in your next release ;-)
Thanks again
Hi Imad.
Glad I could help. The Object.Equals() check worked in my sample, but I can understand it not working based on the source of the image. If somewhere along the lines the image was cloned, this would happen.
I'm not quite sure how we'd be able to implement this as a feature as images don't have any identifiers. Perhaps clicking an image could fire an event that exposes the index into the LeftImages and/or RightImages collection. You can suggest this functionality or something similar as a product idea for future versions at http://ideas.infragistics.com.
Let me know if I can be of further assistance. Thanks,