Home > Back-end >  How to Cancel Devexpress Winforms GridControl CellValueChanged event?
How to Cancel Devexpress Winforms GridControl CellValueChanged event?

Time:02-08

 private void MyGrid_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
    {                     
        //IS_CHECK is a checkbox
        if (e.Column.FieldName == "IS_CHECK")
        {
            if (XMsgBx.ShowInfoYesNo("Asking a Approval") == System.Windows.Forms.DialogResult.Yes)
            {
                //if a user clicks ok then it's ok
            }
            else
            {
                //I want to do something like e.Cancel
                //Want to Cancel the input data from the user

            }               
        }
    } 

I searched that the CellValueChanging() and the CellValueChanged() event in Devexpress GridControl doesn't allow a programmer to unable user typing when the events are called. I found that using ShowingEditor, ValidatingEditor, RepositoryItem, dosen't fit to my faced problem. Is there a way to Cancel the input data from user in any ways uppon the given code? please help..

2022-02-04 edited below

To clarify my question, I have a checkbox name called "IS_CHECK". When I first click, I want to show the messagebox to ask a User whether to save a something menu or not. If the User clicks 'No' then the checkbox shouldn't be checked. If the User clicks 'Yes' then the something menu should be saved. I have already known that the e.Cancel thingy doesn't exists.

CodePudding user response:

You can handle the grid view's ShowingEditor event. This event occurs when a cell's editor is about to open, and allows you to cancel this action.

private void gridView1_ShowingEditor(object sender, CancelEventArgs e) {
    if(gridView1.FocusedColumn.FieldName == "YOUR_FIELD_NAME")
        if(MessageBox.Show("Do you want to change the value?", "Warning", MessageBoxButtons.YesNo) == DialogResult.No)
            e.Cancel = true; }
  •  Tags:  
  • Related