I want to bind a DataTable
to a BindingSource
which is then bound to the GridControl
. How do I add a checkedit control once the DataTable
has been created?
I have a Devexpress windows application which in the designer,
This GridControl
's datasource is the bindingsource1.
I have the following in the page_Load event,
DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("Age");
dt.Rows.Add("rambo", 60);
dt.Rows.Add("Arnie", 35);
bindingSource1.DataSource = dt;
gridView1.RefreshData();
gridView1.Columns.Add(
new DevExpress.XtraGrid.Columns.GridColumn()
{
Caption = "Selected",
ColumnEdit = new RepositoryItemCheckEdit() { },
Visible = true,
}
);
Unfortunately this doesn't seem to work. Any ideas?
Actually, I think you are very close. Try the following changes:
DataTable dt = new DataTable();
dt.Columns.Add("FirstName");
dt.Columns.Add("Age");
dt.Rows.Add("rambo", 60);
dt.Rows.Add("Arnie", 35);
bindingSource1.DataSource = dt;
gridControl1.DataSource = bindingSource1;
gridView1.RefreshData();
gridView1.Columns.Add(
new DevExpress.XtraGrid.Columns.GridColumn()
{
Caption = "Selected",
ColumnEdit = new RepositoryItemCheckEdit() { },
VisibleIndex = 0,
UnboundType = DevExpress.Data.UnboundColumnType.Boolean
}
);
Notice that all I changed was the visible index and setting the unbound column type. Technically, I believe all you need is the visibleIndex property set to where you would like it to appear.