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
460
Hit Test???
posted
I have a list view that I have icons on as well as check boxes. The editor dose a great job handling when the check box is clicked but I was wondering if there was a way to tell if the use clicked the Icon or just the text of the item. The reason I ask is because if they clicked on the icon we want to do something totally different then if they click on just the item. I know you can use a Hit test on other controls but I could not find it on a list view. Please Help.
Parents
No Data
Reply
  • 69832
    Offline posted

    The control does not expose a HitTest method; the closest equivalent would be the UIElement.ElementFromPoint method. The following code sample demonstrates how to use that to determine whether the user clicked on an image:

    private void ultraListView1_MouseDown(object sender, MouseEventArgs e)
    {
        UltraListView listView = sender as UltraListView;
        bool a = this.HitTest( listView, typeof(UltraListViewImageUIElement), e.Location );
        bool stop = true;
    }

    private bool HitTest( UltraListView listView, Type elementType, Point point )
    {
        if ( listView == null || elementType == null )
            return false;

        UIElement controlElement = listView.UIElement;
        UIElement elementAtPoint = controlElement != null ? controlElement.ElementFromPoint( point ) : null;

        while ( elementAtPoint != null )
        {
            if ( elementAtPoint.GetType() == elementType )
                return true;

            elementAtPoint = elementAtPoint.Parent;
        }

        return false;
    }

Children
No Data