網路上找到的都是add新的一個Column上去,這範例比較是我要的
因為偷懶,想用vs工具直接編輯畫面,又想要直接把資料綁上去
DataGridViewComboBoxColumn cboTybe = (DataGridViewComboBoxColumn)this.dataGridView1.Columns[1];
DataTable list = new DataTable();
list.Columns.Add(new DataColumn("Display", typeof(string)));
list.Columns.Add(new DataColumn("Id", typeof(int)));
list.Rows.Add(list.NewRow());
list.Rows.Add(list.NewRow());
list.Rows.Add(list.NewRow());
list.Rows[0][0] = "one";
list.Rows[0][1] = 1;
list.Rows[1][0] = "two";
list.Rows[1][1] = 2;
list.Rows[2][0] = "three";
list.Rows[2][1] = 3;
cboTybe.DataSource = list;
cboTybe.DisplayMember = "Display";
cboTybe.ValueMember = "Id";
沒有留言:
張貼留言