为DataGridView添加下拉列:
DataGridViewComboBoxColumn colShow = new DataGridViewComboBoxColumn();
colShow.Name = "spaceType";
colShow.HeaderText = "空间类型";
colShow.Width = 200;
colShow.Items.Add("选项一");
colShow.Items.Add("选项二");
colShow.DisplayIndex = 0;
dataGridView1.Columns.Insert(0, colShow);
复制代码
设定值:
dataGridView1.Rows[1].Cells[2].Value = "选项二";
设置单击下拉模式(否则需要点两下才能显示下拉框):
DataGridView属性 EditMode 为 EditOnEnter
EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dgv_EditingControlShowing);
为DataGridView添加下拉列:
DataGridViewComboBoxColumn colShow = new DataGridViewComboBoxColumn();
colShow.Name = "spaceType";
colShow.HeaderText = "空间类型";
colShow.Width = 200;
colShow.Items.Add("选项一");
colShow.Items.Add("选项二");
colShow.DisplayIndex = 0;
dataGridView1.Columns.Insert(0, colShow);
复制代码
设定值:
dataGridView1.Rows[1].Cells[2].Value = "选项二";
设置单击下拉模式(否则需要点两下才能显示下拉框):
DataGridView属性 EditMode 为 EditOnEnter
EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dgv_EditingControlShowing);