答案 0 :(得分:0)
我认为这是一个重复的问题。见How to Add Combobox in datagridview only for header?
但是这个链接还有一些很好的示例代码,我在下面复制了这些代码。 MSDN: Dropdown/ComboBox Column Header Cell
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
// Create a ComboBox which will be host in column1's cell
ComboBox comboBoxHeaderCell1 = new ComboBox();
comboBoxHeaderCell1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxHeaderCell1.Visible = true;
comboBoxHeaderCell1.Items.Add("Column1");
comboBoxHeaderCell1.Items.Add("Column2");
// Add the ComboBox to the header cell of column1
dataGridView1.Controls.Add(comboBoxHeaderCell1);
comboBoxHeaderCell1.Location = this.dataGridView1.GetCellDisplayRectangle(0, -1, true).Location;
comboBoxHeaderCell1.Size = this.dataGridView1.Columns[0].HeaderCell.Size;
comboBoxHeaderCell1.Text = "Column1";
}
}