Khi tôi chạy mã của mình, dataGridView TopLeftHeaderCell cũng có một combobox. Làm thế nào tôi có thể thay đổi điều đó?Thêm Hộp tổ hợp vào Tiêu đề DataGridView
Dưới đây là mã của tôi:
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;
}
}
Cảm ơn bạn
Và giải pháp? OP dường như muốn thêm từng combobox vào mỗi columnheader, không đơn giản giải thích tại sao mã của anh ta không hoạt động. –
tôi không có giải pháp vì tôi vẫn không biết tại sao anh ấy sẽ làm điều đó. nếu anh ta sẽ giải thích những gì anh ta muốn làm tôi sẽ có thể giúp –
Tôi cần một combobox cho mỗi tiêu đề trong cột, exept the topLeftHeaderCell – user2576562