We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

doubleclick event not firing (same for mousedoubleclick)

I have an application that calls for a special treatment of grid doubleclick event.

It's not useful the standard routine, edit fields "in position" so allowedit is set to false.

I have tried both doubleclic and mousedoubleclick without success.

The events do not get fired.

If I must allowedit then how can I cancel the standard behavior.

Thanks in advance.

Best regards,

S贸crates A Rivera R

[email protected]


3 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team December 23, 2022 03:27 PM UTC

Hi S贸crates A Rivera R,

Find the response to the queries,

Query

Response


I have an application that calls for a special treatment of grid doubleclick event.

It's not useful the standard routine, edit fields "in position" so allowedit is set to false.

I have tried both doubleclic and mousedoubleclick without success.

The events do not get fired.

 


You cannot handle the Key and Mouse events of the SfDataGrid when raising them, because the TableControl is hosted in the SfDataGrid. So, raise the events for SfDataGrid.TableControl. Please refer to the below code snippet,

//Event subscription

sfDataGrid1.TableControl.DoubleClick += OnDoubleClick;

sfDataGrid1.TableControl.MouseDoubleClick += OnMouseDoubleClick;

 

//Event customization

 private void OnMouseDoubleClick(object sender, MouseEventArgs e)

 {

     Console.WriteLine("OnMouseDoubleClick event triggered");

 }

 

 //Event customization

 private void OnDoubleClick(object sender, System.EventArgs e)

 {

     Console.WriteLine("OnDoubleClick event triggered");

 }       


UG Link: https://help.syncfusion.com/windowsforms/datagrid/gettingstarted?cs-save-lang=1&cs-lang=csharp#handling-events

Note: Have to trigger the control events from SfDataGrid.TableControl instead of SfDataGrid 

SfDataGrid contains the CellClick and CellDoubleClick events support. These events raises when mouse click, and mouse double click in SfDataGrid. Please refer to the below code snippet,

//Event subscription

sfDataGrid1.CellClick += OnCellClick;

sfDataGrid1.CellDoubleClick += OnCellDoubleClick;

 

//Event customization

private void OnCellDoubleClick(object sender, CellClickEventArgs e)

{

    Console.WriteLine("CellDoubleClick event triggered");

}

 

//Event customization

private void OnCellClick(object sender, CellClickEventArgs e)

{

    Console.WriteLine("CellClick event triggered");

}

 


For more information related to cell click, please refer the below user guide documentation link,

UG Link: https://help.syncfusion.com/windowsforms/datagrid/selection#getting-the-cell-value-by-using-cell-click-event

 

 

If I must allowedit then how can I cancel the standard behavior.

 

 

SfDataGrid is not a cell bound control. it is Data bound control. In SfDataGrid.AllowEditing property enable and disable for Column or Grid-based but we do not enable or disable AllowEditing property for a particular cell or row in SfDataGrid. But you can cancel the editing by using SfDataGrid.CurrentCellBeginedit event.

In SfDataGrid value-based editing disable or readonly for currentcell achieve by using SfDataGrid.CurrentCellBeginEdit. Please refer the below code snippet,

Code snippet C# for Editing canceled in SfDataGrid:

//Event subscription

sfDataGrid1.CurrentCellBeginEdit += OnCurrentCellBeginEdit;


//Event customization

private void OnCurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs e)

{

    var recordIndex = sfDataGrid1.TableControl.ResolveToRecordIndex(e.DataRow.RowIndex);

    var record = this.sfDataGrid1.View.Records[recordIndex].Data as DataRowView;

   

    //Here customized the cell value based cancel the Editing

    if (record.Row["Country"] == "Germany")

    {

        e.Cancel = true;

    }

 

 

    //cancel the editing by particualrrow by check the rowindex bsed value

    if (e.DataRow.RowIndex == 5)

    {

        e.Cancel = true;

    }

 

    //cancel the editing by particular column name based

    if (e.DataColumn.GridColumn.MappingName == "CustomerID")

    {

        e.Cancel = true;

    }

}


For more information editing, please refer the below UG link,

UG Link: https://help.syncfusion.com/windowsforms/datagrid/editing#cancel-the-editing-of-the-current-cell

https://help.syncfusion.com/windowsforms/datagrid/editing


Find the sample in the attachment.

Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample_40306276.zip

Marked as answer

SA socrates anibal rivera rivera replied to Vijayarasan Sivanandham December 23, 2022 10:14 PM UTC

Hello.

Thank you very much for your fast response.

Now my app is working.

Thanks again.

Best regards,

S贸crates A Rivera R



VS Vijayarasan Sivanandham Syncfusion Team December 27, 2022 05:16 AM UTC

S贸crates A Rivera R,

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you馃槉.


Loader.
Up arrow icon