Data Grid Clicking

J

John Smith

Hi,

How can I tell on the double click event of the datagrid whether or not a
row was double clicked or a column header was double clicked?

My problem is I open a new form on the double click event of the datagrid
based on the selected row. Users however are used to doubleclicking the
column headers to have them automatically resize the column width to see all
of its contents. Unfortunately when they double click the columns headers,
the event is still fired which opens up the form for the selected row.

So, basically if the double click is on the column header and not a row, I
don't want to open my form...but I don't know how to tell if it is the
column header that is double clicked.

Thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

John,

I would capture the mouse up and mouse down events as well. Every time
the mouse down event or mouse up event occurs, store the coordinates
somewhere. Then, when the double click event fires, pass those coordinates
to the HitTest info. Then, you will know if you are on a row, or a column
or row header.

Granted, there is a slight margin of error here if the user is moving
their mouse erratically while double clicking, but it should work for almost
all cases.

Hope this helps.
 
J

John Smith

Thanks alot. Good idea. I'll give it a shot.

Nicholas Paldino said:
John,

I would capture the mouse up and mouse down events as well. Every time
the mouse down event or mouse up event occurs, store the coordinates
somewhere. Then, when the double click event fires, pass those coordinates
to the HitTest info. Then, you will know if you are on a row, or a column
or row header.

Granted, there is a slight margin of error here if the user is moving
their mouse erratically while double clicking, but it should work for almost
all cases.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John Smith said:
Hi,

How can I tell on the double click event of the datagrid whether or not a
row was double clicked or a column header was double clicked?

My problem is I open a new form on the double click event of the datagrid
based on the selected row. Users however are used to doubleclicking the
column headers to have them automatically resize the column width to see
all
of its contents. Unfortunately when they double click the columns
headers,
the event is still fired which opens up the form for the selected row.

So, basically if the double click is on the column header and not a row, I
don't want to open my form...but I don't know how to tell if it is the
column header that is double clicked.

Thanks!
 
P

perspolis

you can use click event adn then use at that event Hit method to check if a
columnn or row clicked or not
 

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