Determining Item / Subitem Clicked in a ListView

This small code sample shows how to detect where the mouse was clicked in a listview.

Microsoft, in all their wisdom didn’t give us VB developers an easy way to determine where in the listview the mouse was clicked. If you want to place a combo/textbox over a listitem / subitem, it can prove tricky to find out what item was clicked – this code will show you just how to do that.

The code uses the LVHITTESTINFO structure ported from the commctl.h C header file and the LVHT_ constants. The structure will let you know where in the listview the mouse was clicked, including :



  • An Items Icon (including SubItem Icons)

  • On Text

  • On a State Icon

  • Nowhere !


Download zipped project file

Screen-shot

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read