WinForm Note 1: the order of events and edit and edit cells DataGridView TextBox

TextBox edit box

 

When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:

Enter

GotFocus

LostFocus

Leave

Validating

Validated
---------------------

 

Cell Cell

Case of the first order, i.e. without editing Cell:

CellEnter- DataGridView occurs when cells acquire focus, or when the cell receives the input focus.

CellLeave- occurs when the cell loses the input focus, and is now the current cell.

CellValidating- occurs when the cell loses the input focus, while the trigger data verification, data validation.

CellValidated - cells occurs after the completion of data validation.

 

The sequence of events after the second of the cell to edit

CellEnter- DataGridView occurs when cells acquire focus, or when the cell receives the input focus.

CellBeginEdit - occurred in the selected cells when to enter edit mode.

CellLeave- occurs when the cell loses the input focus, and is now the current cell.

CellValidating- occurs when the cell loses the input focus, while the trigger data verification, data validation.

CellValueChanged- value occurs in the cells changed.

CellValidated - cells occurs after the completion of data validation.

CellEndEdit- occurred in the currently selected cell exit edit mode.

application

CellValidating use the event to validate the input data, not legitimate to cancel editing.

 

Private  void dataGridView1_CellValidating ( Object SENDER, DataGridViewCellValidatingEventArgs E) 
{ 
    // editable column 
    IF (e.ColumnIndex =! 2 && e.ColumnIndex =! . 3 )
         return ;
     Double outDb = 0 ;
     IF ( Double .TryParse (e.FormattedValue. the ToString (), OUT outDb)) 
    { 
        the e.Cancel = to false ; 
    } 
    the else 
    { 
        the e.Cancel = to true ; // data format is incorrect then the restore
        dataGridView1.CancelEdit();
    }
}

 

Guess you like

Origin www.cnblogs.com/noigel/p/10931433.html