编辑模式下DatagridView中的ComboBox [英] ComboBox in DatagridView in Edit Mode
问题描述
我正在使用C#框架4.0,Winforms
请参阅具有只读行为的组合框架。
您也可以更改 DisplayStyle
根据 DataGridView
属性的readonly何时更改。将 DisplayStyle
设置为 DataGridViewComboBoxDisplayStyle.Nothing
将隐藏下拉按钮。
例如,使用按钮点击更改 ReadOnly
属性将如下所示:
private void mChangeReadOnlyButton_Click(object sender,EventArgs e)
{
ComboBoxColumn2.DisplayStyle =(dataGridView1.ReadOnly)?
DataGridViewComboBoxDisplayStyle.ComboBox:
DataGridViewComboBoxDisplayStyle.Nothing;
dataGridView1.ReadOnly =!dataGridView1.ReadOnly;
}
可编辑:
可编辑http://i51.tinypic.com/5e7o1w.jpg
ReadOnly:
ReadOnly http://i52.tinypic.com/1zgaxyt.jpg
I have a DataGridView with read-only mode set to true (non-editable) which takes values from a database on form load. When I set the read-only mode to false (editable mode), I want a particular column (eg. Department) to visible as ComboBox so i can select values from there. And when i enter the Read-Only mode, the ComboBox should disappear and DataGridView should be visible as normal. How to achieve it? I am using C# framework 4.0, Winforms
See the implementation at ComboBox with read only behavior.
You could also change the DisplayStyle
based on when the readonly of the DataGridView
property is changed. Setting the DisplayStyle
to DataGridViewComboBoxDisplayStyle.Nothing
will hide the drop down button.
For example, changing the ReadOnly
property with a button click would look something like this:
private void mChangeReadOnlyButton_Click(object sender, EventArgs e)
{
ComboBoxColumn2.DisplayStyle = (dataGridView1.ReadOnly) ?
DataGridViewComboBoxDisplayStyle.ComboBox :
DataGridViewComboBoxDisplayStyle.Nothing;
dataGridView1.ReadOnly = !dataGridView1.ReadOnly;
}
Editable:
Editable http://i51.tinypic.com/5e7o1w.jpg
ReadOnly:
ReadOnly http://i52.tinypic.com/1zgaxyt.jpg
这篇关于编辑模式下DatagridView中的ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!