Print Page | Close Window

[SOLVED] ListView - HitTest fails

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=15347
Printed Date: 07 July 2024 at 2:17pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: [SOLVED] ListView - HitTest fails
Posted By: iamgtd
Subject: [SOLVED] ListView - HitTest fails
Date Posted: 12 October 2009 at 11:15am
The following method delivers wrong results for the selected item in a listview.
 
Is it necessary to convert the mouse event values for x, y?
 
private void axListView1_MouseDownEvent(object sender, AxXtremeSuiteControls._DListViewEvents_MouseDownEvent e)
{
    if (e.button == 2)
    {
        XtremeSuiteControls.ListViewItem listviewitem = axListView1.HitTest(e.x, e.y);
        if (listviewitem != null)
        {
            Debug.WriteLine(listviewitem.Text + " x = " + e.x + ", y = " + e.y);
        }
        else
        {
            Debug.WriteLine("nothing" + " x = " + e.x + ", y = " + e.y);
        }        
    }
}


-------------
---------

OS: Win 10 64 bit

Codejock Version 22.1 ActiveX

MS Visual Studio 2022 - C#

---------



Replies:
Posted By: ijwelch
Date Posted: 12 October 2009 at 12:35pm
See https://forum.codejock.com/forum_posts.asp?TID=15163&KW= - https://forum.codejock.com/forum_posts.asp?TID=15163&KW=

for fix.

Can CJ please deal with this?

-------------
ExtremeSuitePro 12.1.1
WinXP SP3


Posted By: iamgtd
Date Posted: 13 October 2009 at 3:53am
many thanks,
 
is for this solution a code for C# available?


-------------
---------

OS: Win 10 64 bit

Codejock Version 22.1 ActiveX

MS Visual Studio 2022 - C#

---------


Posted By: iamgtd
Date Posted: 13 October 2009 at 4:45am
i have now converted the code to c#. but the result is the same, the function delivers always the first item as selected.
 
any ideas?
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using AxXtremeSuiteControls;

namespace test_contextmenustrip
{
    class codejockHitTest
    {
        const int LVM_FIRST = 0x1000;
        const int LVM_HITTEST = (LVM_FIRST + 18);
        const int LVM_SUBITEMHITTEST = (LVM_FIRST + 57);
        const int LVHT_NOWHERE = 0x1;
        const int LVHT_ONITEMICON = 0x2;
        const int LVHT_ONITEMLABEL = 0x4;
        const int LVHT_ONITEMSTATEICON = 0x8;
        const int LVHT_ONITEM = (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON);

        public struct POINTAPI
        {
            public int x;
            public int y;
        }

        public struct LVHITTESTINFO
        {
            public POINTAPI pt;
            public int flags;
            public int iItem;
            public int iSubItem;
        }

        [DllImport("user32.dll")]
        public static extern int SendMessage(
                      int hWnd,      // handle to destination window
                      uint Msg,       // message
                      long wParam,  // first message parameter
                      LVHITTESTINFO lParam   // second message parameter
                      );

        public static XtremeSuiteControls.ListViewItem ExtremeListView_HitTest(AxXtremeSuiteControls.AxListView lv, int x, int y)
        {
            LVHITTESTINFO HTI = new LVHITTESTINFO();
            HTI.pt.x = x;
            HTI.pt.y = y;
            HTI.flags = LVHT_ONITEM;

            SendMessage(lv.hWnd, LVM_SUBITEMHITTEST, 0, HTI);

            if (HTI.iItem > -1)
            {
                return lv.ListItems[HTI.iItem + 1];
            }
            else
            {
                return null;
            }
        }
    }
}

In the form:
 
private void axListView1_MouseDownEvent(object sender, AxXtremeSuiteControls._DListViewEvents_MouseDownEvent e)
{
    if (e.button == 2)
    {
        XtremeSuiteControls.ListViewItem listviewitem = codejockHitTest.ExtremeListView_HitTest(axListView1, e.x, e.y);
        if (listviewitem != null)
        {
            Debug.WriteLine(listviewitem.Text + " x = " + e.x + ", y = " + e.y);
        }
        else
        {
            Debug.WriteLine("nothing" + " x = " + e.x + ", y = " + e.y);
        }
        ContextMenuStrip1.Show(axListView1,  e.x, e.y);       
    }
}


-------------
---------

OS: Win 10 64 bit

Codejock Version 22.1 ActiveX

MS Visual Studio 2022 - C#

---------


Posted By: iamgtd
Date Posted: 13 October 2009 at 7:37am
I think I have found the solution. The HitTest-method works correct, if the x, y-values are converted.
 
private void axListView1_MouseUpEvent(object sender, AxXtremeSuiteControls._DListViewEvents_MouseUpEvent e)
{
    if (e.button == 2)
    {
        Graphics g = this.CreateGraphics();
        int dpix = (int)g.DpiX;
        int dpiy = (int)g.DpiY;
        g.Dispose();
        XtremeSuiteControls.ListViewItem listviewitem = axListView1.HitTest(e.x * 1440 / dpix, e.y * 1440 / dpiy);
        if (listviewitem != null)
        {
            Debug.WriteLine(listviewitem.Text ");
        }
        else
        {
            Debug.WriteLine("nothing");
        }
        ContextMenuStrip1.Show(axListView1, e.x, e.y);
    }
}


-------------
---------

OS: Win 10 64 bit

Codejock Version 22.1 ActiveX

MS Visual Studio 2022 - C#

---------


Posted By: Oleg
Date Posted: 15 October 2009 at 2:36am
Hi,
 
yes, it works same as Microsoft ListView - coordinates are in Twips to support VB6. You coorectly converted coordinates.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: ijwelch
Date Posted: 15 October 2009 at 7:31am
"coordinates are in Twips to support VB6" ROFL.

Ok but please have this sort of secret info in the help file.



-------------
ExtremeSuitePro 12.1.1
WinXP SP3



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net