Skip to content

DevExpress-Examples/winforms-grid-edit-row-server-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Data Grid - Edit the focused row in DataLayoutControl in Server Mode

Server Mode does not work if you bind the GridControl and DataLayoutControl to the same collection, and use the DataLayoutControl as the grid's Edit Form, because the CurrencyManager does not manage Server Mode Data Sources. All Server Mode data sources except for XPServerCollectionSource are read-only.

This example handles the FocusedRowChanged event to synchronize the DataLayoutControl's data source (XPBindingSource or BindingSource) with the focused row in the GridControl.

Implementation details

  1. Bind the DataLayoutControl to a data source in the Visual Studio Designer.
  • If your ORM is XPO, add the XPBindingSource component from the toolbox.
    1. Rebuild the project.
    2. Select the XPBindingSource.ObjectClassInfo property in the Properties window, open the drop-down list, and choose an appropriate XPO class.
    3. Assign XPBindingSource to the DataLayoutControl.DataSource property.
  • If your ORM is EF or a different library, add the BindingSource component from the toolbox.
    1. Rebuild the project.
    2. Click the Project > Add New Data Source menu item.
    3. Choose the Object Data Source Type and click Next.
    4. Choose an appropriate class in the list and click Finish.
    5. Assign BindingSource to the DataLayoutControl.DataSource property.
  1. Retrieve data fields.
  2. Select the GridView and subscribe to the FocusedRowChanged event.
  3. Use the e.Row property to obtain a data object that corresponds to the focused row and add it to the data source.

Example: XPBindingSource

private void GridView_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) {
    XPBindingSource.DataSource = Session.GetLoadedObjectByKey<ServerSideGridTest>(e.Row);
}
Private Sub GridView_FocusedRowObjectChanged(ByVal sender As Object, ByVal e As FocusedRowObjectChangedEventArgs)
    XPBindingSource.DataSource = Session.GetLoadedObjectByKey(Of ServerSideGridTest)(e.Row)
End Sub

Example: BindingSource

private void GridView_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) {
    object obj = DbContext.ServerSideGridTests.Single(e.Row);
    BindingSource.Clear();
    BindingSource.Add(obj);
}
Private Sub GridView_FocusedRowObjectChanged(ByVal sender As Object, ByVal e As FocusedRowObjectChangedEventArgs)
	Dim obj As Object = DbContext.ServerSideGridTests.Single(e.Row)
	BindingSource.Clear()
	BindingSource.Add(obj)
End Sub

Files to Review