Listview columnclick outside of columns

ListView.ColumnClick does not fire for clicks in the header area that is outside the columns (area to the right of the last column, if any)

Is there any easy way to detect clicks here?

+2


source to share


2 answers


The listview header is a separate object / window inside the listview control. Unfortunately the listview does not contain mouse events with which you can grab any activity in the header (except the obvious ones). You will need to create an extended version of the listview control and use some lower level unmanaged methods to get to that window and make these events available.



You can start here: http://www.codeproject.com/KB/list/HeaderRightClick.aspx .

+2


source


Even at a lower level, this is not easy to do. This article relies on the MenuOpening event, which is not dispatched when the user clicks on the title. In fact, the ListView does not receive any notification when the header (left) is clicked outside the columns.

The ObjectListView (an open source wrapper around the .NET WinForms ListView) has all the necessary plumbing you already need and can be easily modified to do this.



In the HeaderControl.cs file, find the WndProc () method and add it to the case statement, which is:

case 0x0201: //WM_LBUTTONDOWN
    if (this.ColumnIndexUnderCursor == -1) {
        System.Diagnostics.Debug.WriteLine("header click on no column");
    };
    break;

      

+1


source







All Articles