코드를 실행하면 dataGridView TopLeftHeaderCell에도 콤보 상자가 있습니다. 어떻게 바꿀 수 있습니까?DataGridView 머리글에 Combobox 추가
여기 내 코드입니다 :
comboBoxHeaderCell.Location = dataGridView.GetCellDisplayRectangle(i, -1, true).Location;
항상 0,0
반환합니다
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;
}
}
당신에게
코드에서
그리고 해결책은 무엇입니까? OP는 단순히 각 코드가 작동하지 않는 이유를 설명하는 것이 아니라 각 columnheader에 각 콤보 상자를 추가하려는 것 같습니다. –
나는 왜 그럴 수 있을지 아직 모르니까 나는 해결책이 없다. 그는 그가 뭘 원하는지 설명 할게요 내가 도울 수있을거야 –
난 각 열에있는 각 헤더에 대한 combobox가 필요합니다, topLeftHeaderCell – user2576562