如何为来自 System.Data 的 DataRow 的绑定设置 DisplayMemberPath 和 SelectedValuePath?
这就是我正在做的,有错吗?
DataSet ds = new DataSet();
DataTable dt = new DataTable("tb1");
dt.Columns.Add("ID");
dt.Columns.Add("Name");
ds.Tables.Add(dt);
DataRow dr1 = ds.Tables[0].NewRow();
dr1["ID"] = 1;
dr1["Name"] = "Edwin";
DataRow dr2 = ds.Tables[0].NewRow();
dr2["ID"] = 2;
dr2["Name"] = "John";
DataRow dr3 = ds.Tables[0].NewRow();
dr3["ID"] = 3;
dr3["Name"] = "Dave";
ds.Tables[0].Rows.Add(dr1);
ds.Tables[0].Rows.Add(dr2);
ds.Tables[0].Rows.Add(dr3);
comboBox1.DisplayMemberPath = "Name";
comboBox1.SelectedValuePath = "ID";
foreach (DataRow item in ds.Tables[0].Rows)
{
comboBox1.Items.Add(item);
}