One way you can do this is to create a wrapper DataView derived class
that implements ITypedList. Here is code that works with 2
DataGridViews dropped on a form.
namespace WindowsApplication97
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
#region Get the DataSource
DataTable dt = new DataTable("MyTable");
int nCols = 4;
int nRows = 10;
for (int i = 0; i < nCols; i++)
dt.Columns.Add(new DataColumn(string.Format("Col{0}",
i)));
for (int i = 0; i < nRows; ++i)
{
DataRow dr = dt.NewRow();
for (int j = 0; j < nCols; j++)
{
dr[j] = string.Format("row{0} col{1}", i, j);
}
dt.Rows.Add(dr);
}
#endregion
this.dataGridView1.DataSource = dt;
this.dataGridView2.DataSource = new
MyDataViewWrapper(dt.DefaultView, "Col1");
}
}
public class MyDataViewWrapper : DataView, ITypedList
{
DataView dv;
string column;
public MyDataViewWrapper(DataView dv, string column) :
base(dv.Table)
{
this.dv = dv;
this.column = column;
}
#region ITypedList Members
PropertyDescriptorCollection
ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
{
return new PropertyDescriptorCollection(new
PropertyDescriptor[]
{ ((ITypedList)dv).GetItemProperties(listAccessors)[column] });
}
string ITypedList.GetListName(PropertyDescriptor[]
listAccessors)
{
return ((ITypedList)dv).GetListName(listAccessors);
}
#endregion
}
}
=================
Clay Burch
Syncfusion, Inc.