我使用DataTable
名称“grd”,我想在其上绑定数据,但我无法将数据绑定到列。
我在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;
}
:
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;
}
我在gridcontrol上出价:
datatable
但是数据不是X_Age
列中的绑定类型{{1}}。
任何帮助都将受到高度赞赏。
提前致谢!