Print Page | Close Window

Listview DblClick in which column

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=23817
Printed Date: 06 February 2025 at 2:34pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Listview DblClick in which column
Posted By: iamgtd
Subject: Listview DblClick in which column
Date Posted: 13 February 2019 at 7:08am
I'm using the Codejock-Listview-Control with the report view (xtpListViewReport). In the listview there are ListviewItems with some ListviewSubItems.
I use the doubleclick-event to know which item and in which column was doubleclicked.

The DblClick-event is also fired if it is clicked in the area without items. So I can't use the SelectedItem-property to check which item is doubleclicked.

This behaviour I solved with the Hittest-method. This works also if it's vertically scrolled.

To check in which column was clicked, I calc the column-width - see the code. But if there is horizontally scrolled, the result is wrong.

Question: How Can I detect the horizontally scroll-offset?

private void cjListView_DblClick(object sender, EventArgs e)
{
            int f = 16; // it's necessary for a correct result
            XtremeSuiteControls.ListViewItem lvi = cjListView.HitTest((float)currentmouse_x * f, (float)(currentmouse_y - cjListView.Margin.Top) * f);

            if (lvi == null)
            {
                // DblClick was not on a ListViewItem
                return;
            }

     // get the clicked column
            int x_coordinate= cjListView.Margin.Left;
            int selected_col = 0;
            for (int i = 1; i < cjListView.ColumnHeaders.Count + 1; i++)
            {
                x_coordinate += cjListView.ColumnHeaders.Width;
                if (x_coordinate > currentmouse_x)
                {
                    selected_col = i;
                    break;
                }
            }
MessageBox.Show("Hittest: " + lvi.Text + Environment.NewLine + "Column: " + selected_col.ToString());

}

private void cjListView_MouseUpEvent(object sender, AxXtremeSuiteControls._DListViewEvents_MouseUpEvent e)
        {
            currentmouse_x = e.x;
            currentmouse_y = e.y;
        }


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

OS: Win 10 64 bit

Codejock Version 22.1 ActiveX

MS Visual Studio 2022 - C#

---------



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