ColumnView.UpdateCurrentRow() Method

Validates the focused row and saves its values to the data source.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

public override bool UpdateCurrentRow()
Public Overrides Function UpdateCurrentRow As Boolean

Returns

Type Description
Boolean

true if the row has been successfully updated; otherwise, false.

Remarks

The UpdateCurrentRow method raises the ColumnView.ValidateRow event so you can manually specify whether row values are valid. The event handler can leave focus within the row so that end-users can correct row values. In this case, the UpdateCurrentRow method returns false. If focus is allowed to be moved but the row is marked as invalid, the ColumnView.InvalidRowException event is raised. Its handler may force the View to raise an exception, display an error message box or discard changes. Note that the ColumnView.InvalidRowException event can also be raised if row values violate the data source's integrity constraints (it is not always the result of validation).

If row values have been accepted and saved, the UpdateCurrentRow method returns true. This also occurs if changes were discarded. In both cases, the row focus is allowed to be moved. Otherwise, end-users cannot move focus away from the row until its values are corrected.

The UpdateCurrentRow method is automatically called when a row is about to lose focus. The method's return value specifies whether focus movement is allowed. You can call the method manually when you need to determine whether the current row data is valid. For instance, you can call the method after each row cell has been modified and display a warning message if the current value is not accepted.

Please refer to the Modify and Validate Cell Values topic for additional information.

NOTE

Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the UpdateCurrentRow member must not be invoked for these Views. The UpdateCurrentRow member can only be used with real Views that are displayed within the Grid Control. The real Views with which an end-user interacts at runtime can be accessed using the following methods.

The code sample below illustrates how to save the data immediately after the user has changed a cell.


using DevExpress.XtraGrid.Views.Grid;

..

gridView1.ValidateRow += GridView1_ValidateRow;
gridView1.CellValueChanged += GridView1_CellValueChanged;

// Cell validation rules
private void GridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
{
    GridView view = (GridView)sender;
    e.ErrorText = "";
    string productPrice = (string)gridView1.GetRowCellValue(e.RowHandle, "productPrice");
    if(!decimal.TryParse(productPrice))
      e.ErrorText += "Invalid product price. ";
    string productStatus = view.GetRowCellValue(e.RowHandle, "productStatus").ToString();
    if (productStatus!="Active" && productStatus!="Inactive")
        e.ErrorText += "Invalid product status. ";
    if (e.ErrorText != "")
        e.Valid = false;
}

// Save changes immediately when the cell value changes
private void GridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
    GridView view = (GridView)sender;
    if (view.UpdateCurrentRow())
        sqlDataAdapter1.Update(myDataSet, MyTable");
}
See Also