Double Click DataGrid Cell

  • Thread starter Thread starter T. Ford
  • Start date Start date
T

T. Ford

Hey. I've searched far and wide and not found anything
that I could get to work for handling the double click
event of a particular cell. I can get it for an entire
row, but not a particular cell. I tried drilling down to
the TextBox itself and putting an event handler on that
for the double click event, but for some reason it did not
work (possibly not getting propagated down that far?). I
have also seen on this forum this post:

Subject: RE: Double Click a datagrid row
From: "Ying-Shen Yu[MSFT]" <[email protected]>
Sent: 10/31/2003 6:39:33 PM

but I fail to see how this helps with the double click
event for individual cells. Mainly because the double
click event handler takes an EventArgs type rather than a
MouseEventArgs type. Anyone seen any tutorials or have
any examples?

Thanks,

T. Ford
(e-mail address removed)
 
Is the best way to use what Ying-Shen Yu mentioned by
using MouseDown and just checking the Clicks property?

T.Ford
(e-mail address removed)
 
Hi,

For handling double click on datagrid cell, it's much different than
handling the Row, we could customize the
DataGridTextBoxColumn. You may derive from it and override the Edit methods
,provide an dummy Edit method will prevent the TextBox shown. create a
table style and use this Column on the columns you want to handle double
click, handle the datagrid.DoubleClick event. You DataGrid now should be
able to handle this event.
Here is some code snippets:
<code>
class MyColumn : DataGridTextBoxColumn
{
protected override void Edit(CurrencyManager source, int rowNum,
Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
}
}
</code>

snippet to apply the columnstyle on a certain column.
<code>
DataGridTableStyle dtStyle = new DataGridTableStyle();
dtStyle.MappingName = "Categories";
MyColumn col = new MyColumn();
col.MappingName = "CategoryID";
dtStyle.GridColumnStyles.Add(col);
dataGrid1.TableStyles.Add(dtStyle);
</code>

If you still have question on this issue, please be free to reply to this
thread.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.
 
Ying-Shen and Ken,
Thanks for the replys. They are both on the same
lines, and happen to be along the same lines of what I had
tried once already. Obviously what I had tried before was
not correct. I went through the example that Ken pointed
out (which is exactly what Ying-Shen suggested) and
applied the concepts to my project and it worked
perfectly. Thanks again.

T.Ford
(e-mail address removed)
 
Back
Top