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
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();
}
}
}