如何以编程方式将comboBox列显示样式更改为组合框

时间:2013-11-26 02:15:42

标签: c# winforms datagridview

我知道如何在视觉上做到这一点:

右键点击DataGridView ->修改列->设置列类型为DataGridViewComboBoxColumn ->将展示样式设置为comboBox

但我想以编程方式进行。

这是我的代码:

public void initilizeClientsGridView()
{
     DataGridView clientsGridView = new DataGridView();
     DataGridViewColumn comboBoxColumn = new DataGridViewComboBoxColumn();

     clientsGridView.Dock = DockStyle.Fill;
     clientsGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
     panel1.Controls.Add(clientsGridView);

     clientsGridView.Columns.Add("columns","Estatus");
     clientsGridView.Columns.Add("columns", "Razon social");
     clientsGridView.Columns.Add(comboBoxColumn);
}

1 个答案:

答案 0 :(得分:2)

您需要将DataGridViewColumn更改为DataGridViewComboBoxColumn

DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn();
comboBoxColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;