1

BACKGROUND: I've used the VerticalGrid in unbound mode for a few years, where I handle moving data between the editors and my data object using my own code.

Now I'm trying to use it in MultiRecord layout mode

Name: [           ] Name: [           ] Name: [           ]
Addr: [           ] Addr: [           ] Addr: [           ]
City: [           ] City: [           ] City: [           ]

and binding it to the DefaultView of a System.Data.DataTable:

  vGridControl1.DataSource = myDataTable.DefaultView;
  vGridControl1.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;  

However, changes to a record are not being pushed out to the DataView until the edited record loses focus.

QUESTION: Is there a way to put the grid into a mode where the datasource is updated as soon as the cell editor loses focus? For example, if Name is edited, and the user moves to Addr, the datasource immediately reflects the change?

Tim
  • 8,669
  • 31
  • 105
  • 183

1 Answers1

1

You can to this in the ValidatingEditor event as below:

private void vGridControl1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
    {
        vGridControl1.UpdateFocusedRecord();
    }

The following will update the field explicity in the data source without attempting to write the entire record:

        private void vGridControl1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
    {
        var list = vGridControl1.DataSource as IList;
        var record = list[vGridControl1.FocusedRecord] as DataRowView;
        record[vGridControl1.FocusedRow.Index] = e.Value;
    }
jjthebig1
  • 629
  • 7
  • 12
  • Thanks for the suggestion, but there's a conflict if later rows in the grid have an `AllowNull = false` constraint on the underlying DataColumn. This `UpdateFocusedRecord()` approach pushes the entire record to the datasource, whereas I need to push only the current editor's value into the DataSource. – Tim Apr 25 '17 at 13:42
  • 1
    I'm appending the answer with a solution that updates only the focused field in the data source. – jjthebig1 Apr 25 '17 at 20:52
  • Thanks, this gave me some good help. vGridControl.FocusedRow returns the correct object, but vGridControl.FocusedRow.Index returns 0, which is not the correct index of the column in question. However, vGridControl1.FocusedRow.Properties.FieldName or ..Properties.RowHandle get me to the right place in the DataRowView. – Tim Apr 25 '17 at 23:09
  • I have this now: var recordindex = vGridControl1.FocusedRecord; DataRowView drv = (vGridControl1.DataSource as DataView)[recordindex]; drv[vGridControl1.FocusedRow.Properties.FieldName] = e.Value; – Tim Apr 25 '17 at 23:10