我知道如何在视觉上做到这一点:
右键点击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);
}
答案 0 :(得分:2)
您需要将DataGridViewColumn
更改为DataGridViewComboBoxColumn
DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn();
comboBoxColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;