In the WPF DataGrid, quick click appears in addnew or edititem. The deferrefresh transaction process is not allowed.

Source: Internet
Author: User
Tags wpf datagrid

In the project, you have encountered some problems with the DataGrid. This is about the bidirectional binding to the checkbox. After you click "addnew" or "edititem transaction process does not allow deferrefresh,

Or English

The reason is caused by the DataGrid editing status. For details, see the http://stackoverflow.com/questions/3354916/what-is-the-proper-way-to-handle-multiple-datagrids-in-a-tab-control-so-that-cel,

Solution: Add a previewmousedown event to the DataGrid as mentioned above, as shown below:

/// <Summary>
/// Click the mouse to handle the handling of a deferrefresh exception
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void dtgschemeapp_previewmousedown (Object sender, system. Windows. Input. mousebuttoneventargs E)
{
If (isundertabheader (E. originalsource as dependencyobject ))
Committables (this. dtgschemeapp );
}

Private bool isundertabheader (dependencyobject Control)
{
If (control is tabitem)
Return true;
Dependencyobject parent = visualtreehelper. getparent (control );
If (parent = NULL)
Return false;
Return isundertabheader (parent );
}

Private void committables (dependencyobject Control)
{
If (control is DataGrid)
{
DataGrid grid = control as DataGrid;
Grid. commitedit (maid. Row, true );
Return;
}
Int childrencount = visualtreehelper. getchildrencount (control );
For (INT childindex = 0; childindex <childrencount; childindex ++)
Committables (visualtreehelper. getchild (control, childindex ));
}
 

Here, this. dtgschemeapp is the name of the DataGrid. For more information, see.

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.