Skip to content

Edit the focused grid row in DataLayoutControl in Server Mode.

License

Notifications You must be signed in to change notification settings

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f40edaf · Mar 4, 2020

History

3 Commits
Mar 4, 2020
Mar 4, 2020
Mar 4, 2020
Mar 3, 2020
Mar 4, 2020
Mar 3, 2020

Repository files navigation

Files to look at:

Server Mode - How to edit a focused GridView row in DataLayotControl

The standard approach (binding the GridControl and DataLayoutControl to the same collection) does not work in this scenario, because CurrencyManager does not manage Server Mode Data Sources. In addition, all Server Mode Data Sources except for XPServerCollectionSource are read-only.

This example demonstrates how to use the FocusedRowChanged event to synchronize the DataLayoutControl's data source (XPBindingSource or BindingSource) with a focused row.

Implementation details

  1. Bind DataLayoutControl to a data source in the visual 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 fields.
  2. Select GridView and subscribe to the FocusedRowChanged event.
  3. Use the FocusedRowChangedEventArgs.Row property value to retrieve a focused object and add it to the data source.

A code example for XPBindingSource

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

A code example for BindingSource

C#
private void GridView_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) {
    object obj = DbContext.ServerSideGridTests.Single(e.Row);
    BindingSource.Clear();
    BindingSource.Add(obj);
}
VB.NET
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