Override standard MouseClick behaviour in DataGridView

M

Michaela Julia

Hi,

I'm trying to select/deselect a DataGridView row by simply clicking on it

private void datagridview1_MouseClick(object sender, MouseEventArgs e)
{
DataGridView.HitTestInfo info = datagridview1.HitTest(e.X, e.Y);
datagridview1.Rows[info.RowIndex].Selected=
!datagridview1.Rows[info.RowIndex].Selected;
}

Sadly, the standard behaviour for this control is to _always_ select a
row when the user clicks on it ... then "my" event fires and deselects it.
Well, it's almost what I wanted but only quite. 'Cause now I actually
can't _select_ any rows.

Any idea how to let my click event become the one and only? :)

tia
 
A

angshuman

Hi,

I'm trying to select/deselect a DataGridView row by simply clicking on it

private void datagridview1_MouseClick(object sender, MouseEventArgs e)
{
  DataGridView.HitTestInfo info = datagridview1.HitTest(e.X, e.Y);
  datagridview1.Rows[info.RowIndex].Selected=
     !datagridview1.Rows[info.RowIndex].Selected;

}

Sadly, the standard behaviour for this control is to _always_ select a
row  when the user clicks on it ... then "my" event fires and deselectsit.
Well, it's almost what I wanted but only quite. 'Cause now I actually
can't _select_ any  rows.

Any idea how to let my click event become the one and only? :)

tia


Hi,
I think you have to PreFilter the MouseClick message.The
IMessageFilter class in .NET framework allows an application to
capture a windows OS message before it is dispatched to a control or
form.

See here for reference on IFilter - http://www.codeproject.com/KB/cs/imessagefilterarticle.aspx

Hope this helps.

regards
Angshuman
 
M

Michaela Julia

angshuman said:
I think you have to PreFilter the MouseClick message.

This gave me the right idea :)
MouseDown precedes MouseClick. So easy *headdesk*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top