Files to look at:
- MainForm.cs (VB: MainForm.vb)
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.
- Bind DataLayoutControl to a data source in the visual designer.
- If your ORM is XPO, add the XPBindingSource component from the toolbox.
- Rebuild the project.
- Select the XPBindingSource.ObjectClassInfo property in the Properties window, open the drop-down list, and choose an appropriate XPO class.
- Assign XPBindingSource to the DataLayoutControl.DataSource property.
- If your ORM is EF or a different library, add the BindingSource component from the toolbox.
- Rebuild the project.
- Click the Project>Add New Data Source menu item.
- Choose the Object Data Source Type and click Next.
- Choose an appropriate class in the list and click Finish.
- Assign BindingSource to the DataLayoutControl.DataSource property.
- Retrieve fields.
- Select GridView and subscribe to the FocusedRowChanged event.
- Use the FocusedRowChangedEventArgs.Row property value to retrieve a focused object and add it to the data source.
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
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