Example T868102
Visible to All Users

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

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

Example: BindingSource

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

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

BindingListForServerMode/MainForm.cs(vb)
C#
using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Base; using ServerModeGridProjects; namespace BindingListForServerMode { public partial class MainForm :XtraForm { public MainForm() { InitializeComponent(); } private void GridView_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) { BindingSource.DataSource = Session.GetLoadedObjectByKey<ServerSideGridTest>(e.Row); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.