将System.Windows.Form.ComboBox放在Datagridview中并通过键盘操作

本文关键字:键盘 操作 Datagridview Windows System Form ComboBox 放在 | 更新日期: 2023-09-27 18:28:06

private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.CurrentCell.ColumnIndex==0)
    {
        dataGridView1.BeginEdit(true);
        comboBox1.Visible = true;
        comboBox1.Location = dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;
        comboBox1.Size = dataGridView1.CurrentCell.Size;
        comboBox1.Focus();
    }
}

在上面的代码中,组合框下拉列表属性不起作用

将System.Windows.Form.ComboBox放在Datagridview中并通过键盘操作

您可以使用以下代码设置新的"组合框行":

法典

        DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
        dataGridView1.Columns.Add(chk);
        chk.HeaderText = "Check Data";
        chk.Name = "chk";
        dataGridView1.Rows[2].Cells[3].Value = true;

我希望这能解决你的问题!有好的一天。