Double-click event of the DataGrid and write it by yourself

Source: Internet
Author: User

The primary reason why the double-click event of the cell row of the DataGrid does not work is that the DataGrid treats a cell as a TextBox, so no double-click event is generated.

The code for the solution is as follows:

DataGrid dg = this. Maid;
Dg. TableStyles. Clear ();
DataGridTableStyle tableStyle = new DataGridTableStyle ();
TableStyle. MappingName = "whp ";
// Set attributes
TableStyle. AlternatingBackColor = Color. LightGray;

Maid ();
TextStyle. MappingName = "ID ";
TextStyle. HeaderText = "ID ";
TextStyle. Width = 0;
Dg. MouseDown + = new System. Windows. Forms. MouseEventHandler (dg_MouseDown );

// Add an event Processor
TextStyle. TextBox. MouseDown + = new MouseEventHandler (TextBoxMouseDownHandler );
TextStyle. TextBox. DoubleClick + = new EventHandler (TextBoxDoubleClickHandler );
TableStyle. GridColumnStyles. Add (textStyle );

TextStyle = new maid ();
TextStyle. MappingName = "name ";
TextStyle. HeaderText = "name ";
TextStyle. Width = 660;

// Add an event Processor
TextStyle. TextBox. MouseDown + = new MouseEventHandler (TextBoxMouseDownHandler );
TextStyle. TextBox. DoubleClick + = new EventHandler (TextBoxDoubleClickHandler );
TableStyle. GridColumnStyles. Add (textStyle );

Dg. TableStyles. Add (tableStyle );

Dg. DataSource = SQL. CasehxmQueryResult (conditionName, likeName). Tables ["whp"]. DefaultView;

}

Private void TextBoxDoubleClickHandler (object sender, EventArgs e)
{
Int id = Convert. ToInt32 (maid [maid. RowNumber, 0]);
ShowWebBrowser (id );

}

Private void TextBoxMouseDownHandler (object sender, MouseEventArgs e)
{
If (DateTime. Now <gridMouseDownTime. AddMilliseconds (SystemInformation. DoubleClickTime ))
{
Int id = Convert. ToInt32 (maid [maid. RowNumber, 0]);
ShowWebBrowser (id );

}

}

Private void dg_MouseDown (object sender, System. Windows. Forms. MouseEventArgs e)
{
GridMouseDownTime = DateTime. Now;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.