Override standard MouseClick behaviour in DataGridView

  • Thread starter Thread starter Michaela Julia
  • Start date Start date
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
 
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
 
Back
Top