Back to Devexpress

BaseView.PostEditor() Method

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-baseview-5f081c39.md

latest11.0 KB
Original Source

BaseView.PostEditor() Method

Saves the modified cell value to the data source. If the GridOptionsView.RowAutoHeight setting is disabled, the currently active cell editor remains opened.

Namespace : DevExpress.XtraGrid.Views.Base

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
public bool PostEditor()
vb
Public Function PostEditor As Boolean

Returns

TypeDescription
Boolean

true if the value has been successfully saved to the data source; otherwise, false.

|

Remarks

Note

Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the PostEditor member must not be invoked for these Views. The PostEditor 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.

Tip

The following in-place editors can post their value to the bound data source immediately after the value changes:

  • CheckEdit
  • ToggleSwitch
  • RadioGroup
  • TrackBarControl
  • RatingControl
  • PopupBaseEdit descendants

Use the editor’s InplaceModeImmediatePostChanges property to control this behavior. The WindowsFormsSettings.InplaceEditorUpdateMode property allows you to control update behavior globally.

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.

csharp
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();
}
vb
Dim rItemTextEdit As New RepositoryItemTextEdit()
AddHandler rItemTextEdit.EditValueChanged, AddressOf RItemTextEdit_EditValueChanged
GridControl1.RepositoryItems.Add(rItemTextEdit)
GridColumn1.ColumnEdit = rItemTextEdit

Private Sub RItemTextEdit_EditValueChanged(sender As Object, e As EventArgs)
    If GridView1.PostEditor() Then
        GridView1.UpdateCurrentRow()
    End If
End Sub

Example: Immediately save a Boolean column’s check state to a data source

To save a Boolean column’s check state to a data source once a user toggles the check box, ensure that a check edit in-place editor (RepositoryItemCheckEdit) is assigned to a column. Then handle the RepositoryItem.EditValueChanged event to call the View’s PostEditor and UpdateCurrentRow methods.

csharp
RepositoryItemCheckEdit checkEdit = new RepositoryItemCheckEdit();
checkEdit.EditValueChanged += repositoryItemCheckEdit_EditValueChanged;
gridControl1.RepositoryItems.Add(checkEdit);
gridView1.Columns["Marked"].ColumnEdit = checkEdit;

private void repositoryItemCheckEdit_EditValueChanged(object sender, EventArgs e) {
    if(gridView.PostEditor()) {
        gridView.UpdateCurrentRow();
    }  
}
vb
Private checkEdit As New RepositoryItemCheckEdit()
Private checkEdit.EditValueChanged += AddressOf repositoryItemCheckEdit_EditValueChanged
gridControl1.RepositoryItems.Add(checkEdit)
gridView1.Columns("Marked").ColumnEdit = checkEdit

Private Sub repositoryItemCheckEdit_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
    If gridView.PostEditor() Then
        gridView.UpdateCurrentRow()
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the PostEditor() 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.

winforms-filter-lookup-column-based-on-another-lookup-column/CS/DxSample/MainForm.cs#L31

csharp
private void CountryEditor_EditValueChanged(object sender, EventArgs e) {
    this.GridView.PostEditor();
    this.GridView.SetFocusedRowCellValue("CityCode", null);

winforms-grid-auto-add-new-row-after-editing-last-cell/CS/Form1.cs#L81

csharp
if (_View.IsNewItemRow(_View.FocusedRowHandle)) {
    _View.PostEditor();
    _View.UpdateCurrentRow();

winforms-grid-use-layoutview-as-master-view/CS/WindowsApplication3/MasterDetailHelper.cs#L142

csharp
void OnCloseUp(object sender, DevExpress.XtraEditors.Controls.CloseUpEventArgs e) {
    DetailView.PostEditor();
    detailView.UpdateCurrentRow();

winforms-grid-add-radio-group-column/CS/Helper/GridRadioGroupColumnHelper.cs#L103

csharp
{
    _GridView.PostEditor();
}

winforms-grid-update-row-style-on-cell-value-change/CS/Form1.cs#L61

csharp
{
    gridView1.PostEditor();
}

winforms-filter-lookup-column-based-on-another-lookup-column/VB/DxSample/MainForm.vb#L33

vb
Private Sub CountryEditor_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles CountryEditor.EditValueChanged
    Me.GridView.PostEditor()
    Me.GridView.SetFocusedRowCellValue("CityCode", Nothing)

winforms-grid-auto-add-new-row-after-editing-last-cell/VB/Form1.vb#L74

vb
If _View.IsNewItemRow(_View.FocusedRowHandle) Then
    _View.PostEditor()
    _View.UpdateCurrentRow()

winforms-grid-use-layoutview-as-master-view/VB/WindowsApplication3/MasterDetailHelper.vb#L153

vb
Private Sub OnCloseUp(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.CloseUpEventArgs)
    DetailView.PostEditor()
    detailView_Renamed.UpdateCurrentRow()

winforms-grid-add-radio-group-column/VB/Helper/GridRadioGroupColumnHelper.vb#L102

vb
Private Sub RadioRepositoryItem_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
    _GridView.PostEditor()
End Sub

winforms-grid-update-row-style-on-cell-value-change/VB/Form1.vb#L57

vb
Private Sub OnEditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
    gridView1.PostEditor()
End Sub

See Also

ActiveEditor

CloseEditor()

HideEditor()

ShowEditor()

UpdateCurrentRow()

BaseView Class

BaseView Members

DevExpress.XtraGrid.Views.Base Namespace