ColumnView.UpdateCurrentRow() Method
Validates the focused row and saves its values to the data source.
Namespace: DevExpress.XtraGrid.Views.Base
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
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 Views that display real data within the Grid Control. Use the following methods to access these Views with which an end user interacts at runtime.
- GridControl.MainView - returns the top most View in a grid;
- GridControl.FocusedView - returns the focused View;
- GridControl.DefaultView - returns the currently maximized View;
- the sender parameter of View specific events;
- GridView.GetDetailView - returns a detail clone View for a specific master row.
Example: Immediately update the View on cell value changes
Assume that the content or appearance settings of a View’s specific elements are dependent on cell values, and you want to update these elements immediately after a cell value is changed. For instance, you may want to calculate a custom summary or apply conditional formatting after a user changes a cell value.
To perform this task, ensure that an in-place editor (a RepositoryItem descendant) is assigned to a column. Then handle an in-place editor’s RepositoryItem.EditValueChanged event, and call a Data Grid View’s PostEditor and UpdateCurrentRow
methods.
RepositoryItemTextEdit rItemTextEdit = new RepositoryItemTextEdit();
rItemTextEdit.EditValueChanged += RItemTextEdit_EditValueChanged;
gridControl1.RepositoryItems.Add(rItemTextEdit);
gridColumn1.ColumnEdit = rItemTextEdit;
private void RItemTextEdit_EditValueChanged(object sender, EventArgs e) {
if(gridView1.PostEditor())
gridView1.UpdateCurrentRow();
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the UpdateCurrentRow() method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.