我使用dxg:GridControl
名称“grd”,我想在其上绑定数据,但我无法将数据绑定到列。我有一个DataTable
for 绑定gridcontrol
:
public DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Age", typeof(DataTable));
DataTable xdt = new DataTable();
xdt.Columns.Add("DS", typeof(string));
DataRow xdr = xdt.NewRow();
xdr["DS"] = "item1";
xdt.Rows.Add(xdr);
DataRow xxdr = xdt.NewRow();
xxdr["DS"] = "item2";
xdt.Rows.Add(xxdr);
DataRow dr = dt.NewRow();
dr["Name"] = "TrieuLe";
dr["Age"] = xdt;
dt.Rows.Add(dr);
return dt;
}
我竞标 gridcontrol :
private void InitGrid()
{
try
{
GridColumn col = null;
col = new GridColumn();
col.FieldName = "Name";
col.Header = "Character name";
col.Width = 50;
grd.Columns.Add(col);
col = new GridColumn();
col.FieldName = "Age";
col.Header = "X_Age";
col.EditSettings = new ListBoxEditSettings();
((ListBoxEditSettings)col.EditSettings).DisplayMember = "DS";
((ListBoxEditSettings)col.EditSettings).ValueMember = "DS";
col.Width = 50;
grd.Columns.Add(col);
}
catch (Exception ex)
{
throw ex;
}
}
public frm_Main()
{
InitializeComponent();
InitGrid();
DataTable xdt = null;
xdt = GetData();
grd.ItemsSource = xdt;
}
但数据不是datatable
列中的绑定类型X_Age
。
任何帮助将不胜感激。
提前致谢!