ListView.ColumnClick doesn't seem to fire for clicks in the header area that is outside the columns (area to the right of the last column, if there is any)
is there some easy way to detect clicks here?
ListView.ColumnClick doesn't seem to fire for clicks in the header area that is outside the columns (area to the right of the last column, if there is any)
is there some easy way to detect clicks here?
The listview header is a seperate entity/window inside the listview control. Unfortunately listview provides no mouse events with which you can capture any activity on the header (except the obvious ones). You are going to have to create extended version of the listview control and use some lower level unmanaged methods to get to that window and make those events available.
You can start here: http://www.codeproject.com/KB/list/HeaderRightClick.aspx.
Even at a lower level, this is not that easy to do. The given article relies on the MenuOpening event, which is not sent when the user left clicks on the header. In fact, the ListView doesn't receive any notification when the header is (left) clicked outside of the columns.
ObjectListView (an open source wrapper around .NET WinForms ListView) has all the plumbing you need already in place and can be easily modified to do this.
In the file HeaderControl.cs, look for the WndProc() method and add this to the case statement that is there:
case 0x0201: //WM_LBUTTONDOWN
if (this.ColumnIndexUnderCursor == -1) {
System.Diagnostics.Debug.WriteLine("header click on no column");
};
break;