mouseclick event??

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?
 
G

Guest

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
 
G

Guest

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
 
G

Guest

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
 

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