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.
- Bind the
DataLayoutControl
to a data source in the Visual Studio 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 data fields.
- Select the
GridView
and subscribe to the FocusedRowChanged event. - Use the
e.Row
property to obtain a data object that corresponds to the focused row and add it to the data source.
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
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
- MainForm.cs (VB: MainForm.vb)
(you will be redirected to DevExpress.com to submit your response)