当我运行我的代码时,dataGridView TopLeftHeaderCell 也有一个组合框。我该如何改变呢?
这是我的代码:
public void AddHeaders(DataGridView dataGridView)
{
for (int i = 0; i < 4; i++)
{
// Create a ComboBox which will be host a column's cell
ComboBox comboBoxHeaderCell = new ComboBox();
comboBoxHeaderCell.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxHeaderCell.Visible = true;
foreach (KeyValuePair<string, string> label in _labels)
{
comboBoxHeaderCell.Items.Add(label.Key);
}
// Add the ComboBox to the header cell of the column
dataGridView.Controls.Add(comboBoxHeaderCell);
comboBoxHeaderCell.Location = dataGridView.GetCellDisplayRectangle(i, -1, true).Location;
comboBoxHeaderCell.Size = dataGridView.Columns[0].HeaderCell.Size;
comboBoxHeaderCell.Text = _labels[i].Key;
}
}
谢谢