Example E2805
Visible to All Users

WinForms Data Grid - Bind to a queryable source (LinqInstantFeedbackSource)

This example shows how to bind the WinForms Data Grid to LinqInstantFeedbackSource.

Set the LinqInstantFeedbackSource.KeyExpression property to a key property name.

C#
linqInstantFeedbackSource.KeyExpression = "SupplierID";

Handle the LinqInstantFeedbackSource.GetQueryable event. Set the e.QueryableSource property.

C#
void OnGetQueryable(object sender, GetQueryableEventArgs e) { NorthwindClassesDataContext dt = new NorthwindClassesDataContext(); e.QueryableSource = dt.Suppliers; e.Tag = dt; }

Handle the LinqInstantFeedbackSource.DismissQueryable event to dispose of a DataContext object when it is no longer required.

C#
void OnDismissQueryable(object sender, GetQueryableEventArgs e) { (e.Tag as NorthwindClassesDataContext).Dispose(); }

Bind LinqInstantFeedbackSource to the Grid control.

C#
gridControl1.DataSource = linqInstantFeedbackSource;

Files to Review

See Also

Does this example address your development requirements/objectives?

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

Example Code

LinqServerMode/Main.cs(vb)
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using DevExpress.XtraGrid.Views.Grid; using DevExpress.Data.Linq; using DevExpress.XtraEditors; namespace LinqServerMode { public partial class Main : XtraForm { public Main() { InitializeComponent(); linqInstantFeedbackSource.KeyExpression = "SupplierID"; gridControl1.DataSource = linqInstantFeedbackSource; } void OnGetQueryable(object sender, GetQueryableEventArgs e) { NorthwindClassesDataContext dt = new NorthwindClassesDataContext(); e.QueryableSource = dt.Suppliers; e.Tag = dt; } void OnDismissQueryable(object sender, GetQueryableEventArgs e) { (e.Tag as NorthwindClassesDataContext).Dispose(); } } }

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.