mouseclick event??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

In my windowsformapplication I have a DataGrid where the rowheader is not
visible, and readOnly = true. The grid is bound to a DataView where
AllowEdit, AllowNew and AllowDelete is set to false.

To be able to select an entire row on mouseclick I've created a MouseUp event.

Private void DataGrid1_MouseUp (object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point pt = new Point (e.X, e.Y);
this.DataGrid1.Select(this.DataGrid1.HitTest1(pt).Row);
}

My problem occures when I click outside or under my last row. I recieve
following message: "Index was outside the bounds of the array" with choice to
continue or quit.

How do I prevent this to happen?
 
Hi Hans,

It seems that your HitTest(...) returns row index outside
the datagrid range.
E.g. if row index is -1 then it means that
no row was at this point.

To prevent this happen you should:
1. get row index
2. check if its greater or equal to zero
3. if true then select wanted row

Regards

Marcin
 
THANK YOU :-)

---< Hans >---

Marcin Grzębski said:
Hi Hans,

It seems that your HitTest(...) returns row index outside
the datagrid range.
E.g. if row index is -1 then it means that
no row was at this point.

To prevent this happen you should:
1. get row index
2. check if its greater or equal to zero
3. if true then select wanted row

Regards

Marcin
 
It worked !!!

THANK YOU
--- < Hans > ---

Marcin Grzębski said:
Hi Hans,

It seems that your HitTest(...) returns row index outside
the datagrid range.
E.g. if row index is -1 then it means that
no row was at this point.

To prevent this happen you should:
1. get row index
2. check if its greater or equal to zero
3. if true then select wanted row

Regards

Marcin
 
Back
Top