我有一个包含DataGridView
的winform项目。
有专栏:
this.ColumnComboBox.FillWeight = 103.2981F;
this.ColumnComboBox.HeaderText = "Test ComboBox";
this.ColumnComboBox.Items.AddRange(new object[] {
"test1",
"test2",
"test3"});
this.ColumnComboBox.Name = "ColumnComboBox";
this.ColumnComboBox.ReadOnly = true;
我尝试在[设计]窗口中将ReadOnly
设置为false,但设计人员总是将其替换为上面的代码。
此外,我的DataGridView包含此事件:
private void Gridview1_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
switch (e.ColumnIndex)
{
// ComboBoxColumn
case 3:
DataGridViewComboBoxCell comboCell = Gridview1.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewComboBoxCell;
if (listItem[e.RowIndex] is DisplayComboClass)
{
comboCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
}
else
{
comboCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
}
break;
}
}
我不知道为什么,但是当我运行我的项目时,我的DataGridView会在需要时显示组合框,但我无法选择一个值。当我点击它时,没有任何反应,值“test1 / 2/3”没有出现。
答案 0 :(得分:2)
尝试,
DataGridView.ReadOnly = false;
在InitializeComponent()
之后,
希望有所帮助,