构造DataTable
手动构造一个DataTable:
1 DataTable dt = new DataTable(); 2 dt.Columns.Add("ID", typeof(string)); 3 dt.Columns.Add("Name", typeof(string)); 4 DataRow _Row1 = dt.NewRow(); 5 _Row1["ID"] = "1"; 6 _Row1["Name"] = "男"; 7 dt.Rows.Add(_Row1); 8 DataRow _Row2 = dt.NewRow(); 9 _Row2["ID"] = "0"; 10 _Row2["Name"] = "女"; 11 dt.Rows.Add(_Row2); 12 comboBox1.DisplayMember = "Name"; 13 comboBox1.ValueMember = "ID"; 14 comboBox1.DataSource = dt;