Click here to Skip to main content
15,887,870 members
Home / Discussions / C#
   

C#

 
GeneralRe: Character encoding when reading a text file of unknown encoding, to create an XML file Pin
JohnLBevan24-Aug-10 22:33
professionalJohnLBevan24-Aug-10 22:33 
QuestionStrange order of events in ListView with MultiSelect set to false Pin
crypto_rsa24-Aug-10 6:28
crypto_rsa24-Aug-10 6:28 
AnswerRe: Strange order of events in ListView with MultiSelect set to false Pin
Ravi Bhavnani24-Aug-10 8:17
professionalRavi Bhavnani24-Aug-10 8:17 
AnswerRe: Strange order of events in ListView with MultiSelect set to false Pin
DaveyM6924-Aug-10 10:16
professionalDaveyM6924-Aug-10 10:16 
GeneralRe: Strange order of events in ListView with MultiSelect set to false Pin
crypto_rsa24-Aug-10 21:37
crypto_rsa24-Aug-10 21:37 
GeneralRe: Strange order of events in ListView with MultiSelect set to false Pin
johannesnestler24-Aug-10 23:05
johannesnestler24-Aug-10 23:05 
AnswerRe: Strange order of events in ListView with MultiSelect set to false Pin
DaveyM6924-Aug-10 10:41
professionalDaveyM6924-Aug-10 10:41 
GeneralRe: Strange order of events in ListView with MultiSelect set to false Pin
crypto_rsa25-Aug-10 1:12
crypto_rsa25-Aug-10 1:12 
Thanks for the proposed semi-solution. I put together different pieces and came up with this solution which seems to do what I want Smile | :) 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 | :confused:
QuestionEditable datagridview Pin
saqib8224-Aug-10 5:37
saqib8224-Aug-10 5:37 
AnswerRe: Editable datagridview Pin
dan!sh 24-Aug-10 6:00
professional dan!sh 24-Aug-10 6:00 
GeneralRe: Editable datagridview Pin
saqib8224-Aug-10 6:07
saqib8224-Aug-10 6:07 
GeneralRe: Editable datagridview Pin
dan!sh 24-Aug-10 6:24
professional dan!sh 24-Aug-10 6:24 
GeneralRe: Editable datagridview Pin
saqib8224-Aug-10 6:39
saqib8224-Aug-10 6:39 
AnswerRe: Editable datagridview Pin
Mada Naga Sankar25-Aug-10 19:38
Mada Naga Sankar25-Aug-10 19:38 
Questionproblem with invoke method. it says cannot call invoke on a control until the window handle has been created Pin
prasadbuddhika24-Aug-10 4:59
prasadbuddhika24-Aug-10 4:59 
AnswerRe: problem with invoke method. it says cannot call invoke on a control until the window handle has been created Pin
Luc Pattyn24-Aug-10 5:32
sitebuilderLuc Pattyn24-Aug-10 5:32 
AnswerRe: problem with invoke method. it says cannot call invoke on a control until the window handle has been created Pin
Chris Trelawny-Ross24-Aug-10 5:34
Chris Trelawny-Ross24-Aug-10 5:34 
AnswerRe: problem with invoke method. it says cannot call invoke on a control until the window handle has been created [modified] Pin
DaveyM6924-Aug-10 9:14
professionalDaveyM6924-Aug-10 9:14 
QuestionCollection of stuct object - does the GC will run ? Pin
Yanshof24-Aug-10 2:20
Yanshof24-Aug-10 2:20 
AnswerRe: Collection of stuct object - does the GC will run ? Pin
Ian Shlasko24-Aug-10 2:43
Ian Shlasko24-Aug-10 2:43 
GeneralRe: Collection of stuct object - does the GC will run ? Pin
Łukasz Nowakowski24-Aug-10 2:57
Łukasz Nowakowski24-Aug-10 2:57 
GeneralRe: Collection of stuct object - does the GC will run ? Pin
Paul Michalik24-Aug-10 23:01
Paul Michalik24-Aug-10 23:01 
AnswerRe: Collection of stuct object - does the GC will run ? Pin
Luc Pattyn24-Aug-10 2:56
sitebuilderLuc Pattyn24-Aug-10 2:56 
AnswerRe: Collection of stuct object - does the GC will run ? Pin
johannesnestler24-Aug-10 4:29
johannesnestler24-Aug-10 4:29 
GeneralRe: Collection of struct object - does the GC will run ? Pin
Yanshof24-Aug-10 5:03
Yanshof24-Aug-10 5:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.