Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Controls
  New Posts New Posts RSS Feed - [SOLVED] ListView - HitTest fails
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

[SOLVED] ListView - HitTest fails

 Post Reply Post Reply
Author
Message
iamgtd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 February 2009
Status: Offline
Points: 131
Post Options Post Options   Thanks (0) Thanks(0)   Quote iamgtd Quote  Post ReplyReply Direct Link To This Post Topic: [SOLVED] ListView - HitTest fails
    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#

---------
Back to Top
ijwelch View Drop Down
Senior Member
Senior Member


Joined: 20 June 2006
Status: Offline
Points: 262
Post Options Post Options   Thanks (0) Thanks(0)   Quote ijwelch Quote  Post ReplyReply Direct Link To This Post Posted: 12 October 2009 at 12:35pm
See https://forum.codejock.com/forum_posts.asp?TID=15163&KW=

for fix.

Can CJ please deal with this?
ExtremeSuitePro 12.1.1
WinXP SP3
Back to Top
iamgtd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 February 2009
Status: Offline
Points: 131
Post Options Post Options   Thanks (0) Thanks(0)   Quote iamgtd Quote  Post ReplyReply Direct Link To This Post 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#

---------
Back to Top
iamgtd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 February 2009
Status: Offline
Points: 131
Post Options Post Options   Thanks (0) Thanks(0)   Quote iamgtd Quote  Post ReplyReply Direct Link To This Post 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#

---------
Back to Top
iamgtd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 February 2009
Status: Offline
Points: 131
Post Options Post Options   Thanks (0) Thanks(0)   Quote iamgtd Quote  Post ReplyReply Direct Link To This Post 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#

---------
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
ijwelch View Drop Down
Senior Member
Senior Member


Joined: 20 June 2006
Status: Offline
Points: 262
Post Options Post Options   Thanks (0) Thanks(0)   Quote ijwelch Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.155 seconds.