Article ID: 125694 - Last Review: July 11, 2005 - Revision: 1.3 How To Find Out Which Listview Column Was Right-ClickedThis article was previously published under Q125694 On This PageSUMMARY
You can use the technique described in this article to find out which
column was clicked after right-clicking the listview column header.
MORE INFORMATION
LVN_COLUMNCLICK notifies a listview's parent window when a column is
clicked using the left mouse button, but no such notification occurs when a
column is clicked with the right mouse button.
Windows 95 sends an NM_RCLICK notification to the listview's parent window when a column is clicked with the right mouse button, but the message sent does not contain any information as to which column was clicked, especially if the window is sized so that the listview is scrolled to the right. The correct way to determine which column was clicked with the right mouse button, regardless of whether the listview is scrolled, is to send the header control an HDM_HITTEST message, which returns the index of the column that was clicked in the iItem member of the HD_HITTESTINFO struct. In sending this message, make sure the point passed in the HD_HITTESTINFO structure is relative to the header control's client coordinates. Do not pass it a point relative to the listview's client coordinates; if you do, it will return an incorrect column index value. The header control in this case turns out to be a child of the listview control of LVS_REPORT style. The following code demonstrates this method. Note that while the code processes the NM_RCLICK notification on a WM_NOTIFY message, you also process the WM_CONTEXTMENU message, which is also received as a notification when the user clicks the right mouse button. Sample Code
| Article Translations
|

Back to the top
