Thanks for the proposed semi-solution. I put together different pieces and came up with this solution which seems to do what I want :) First, I leave the MultiSelect property set to false and set FullRowSelect to true. Then I use this code:
public class CustomListView : ListView
{
public CustomListView()
{
InitializeComponent();
}
bool fakeMouseUp = false;
bool mouseDownOnItem = false;
protected override void OnMouseDown( MouseEventArgs e )
{
// if we're not on an item or subitem, we will get OnMouseUp immediately
mouseDownOnItem = HitTest( e.Location ).Item != null;
Debug.WriteLine( "OnMouseDown" );
base.OnMouseDown( e );
}
protected override void OnMouseUp( MouseEventArgs e )
{
if( mouseDownOnItem || fakeMouseUp )
{
Debug.WriteLine( "OnMouseUp" );
mouseDownOnItem = false;
fakeMouseUp = false;
base.OnMouseUp( e );
}
}
protected override void WndProc( ref Message m )
{
if( !mouseDownOnItem && m.Msg == 0x0202 /\*WM\_LBUTTONUP\*/ )
{
// send a fake MouseUp event
fakeMouseUp = true;
Point point = new Point( ((int) m.LParam) & 0x0000FFFF, (int) m.LParam >> 16 );
OnMouseUp( new MouseEventArgs( MouseButtons.Left, 1, point.X, point.Y, 0 ) );
}
base.WndProc( ref m );
}
}
But I always have a feeling of wasted time when I need to do such workarounds for weird .NET behaviour. Why on Earth do I get a MouseUp event when the mouse button was not physically released? :confused: