[SOLVED] ListView - HitTest fails |
Post Reply |
Author | |
iamgtd
Senior Member Joined: 25 February 2009 Status: Offline Points: 131 |
Post Options
Thanks(0)
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# --------- |
|
ijwelch
Senior Member Joined: 20 June 2006 Status: Offline Points: 262 |
Post Options
Thanks(0)
|
ExtremeSuitePro 12.1.1
WinXP SP3 |
|
iamgtd
Senior Member Joined: 25 February 2009 Status: Offline Points: 131 |
Post Options
Thanks(0)
|
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# --------- |
|
iamgtd
Senior Member Joined: 25 February 2009 Status: Offline Points: 131 |
Post Options
Thanks(0)
|
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 public struct POINTAPI public struct LVHITTESTINFO [DllImport("user32.dll")] public static XtremeSuiteControls.ListViewItem ExtremeListView_HitTest(AxXtremeSuiteControls.AxListView lv, int x, int y) SendMessage(lv.hWnd, LVM_SUBITEMHITTEST, 0, HTI); if (HTI.iItem > -1) 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# --------- |
|
iamgtd
Senior Member Joined: 25 February 2009 Status: Offline Points: 131 |
Post Options
Thanks(0)
|
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# --------- |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
ijwelch
Senior Member Joined: 20 June 2006 Status: Offline Points: 262 |
Post Options
Thanks(0)
|
"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 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |