本文介绍了如何在windows窗体中的datagridview中显示组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下程序在datagridview中显示一个组合框,当它们聚焦在那个单元格时,如何在固定列的任何单元格中显示它。
谢谢提前..
我的尝试:
i have following procedure to display a combobox in datagridview , how to display it in any cell of a fixed column when their is focus on that cell .
thanks in advance ..
What I have tried:
private void Show_Combobox(int iRowIndex, int iColumnIndex)
{
// DESCRIPTION: SHOW THE COMBO BOX IN THE SELECTED CELL OF THE GRID.
// PARAMETERS: iRowIndex - THE ROW ID OF THE GRID.
// iColumnIndex - THE COLUMN ID OF THE GRID.
int x = 0;
int y = 0;
int Width = 0;
int height = 0;
// GET THE ACTIVE CELL'S DIMENTIONS TO BIND THE COMBOBOX WITH IT.
Rectangle rect = default(Rectangle);
rect = dataGridView1.GetCellDisplayRectangle(iColumnIndex, iRowIndex, false);
x = rect.X + dataGridView1.Left;
y = rect.Y + dataGridView1.Top;
Width = rect.Width;
height = rect.Height;
comboBox1.SetBounds(x, y, Width, height);
comboBox1.Visible = true;
comboBox1.Focus();
}
推荐答案
DataGridViewComboBoxColumn dgvCombo = new DataGridViewComboBoxColumn();
dgvCombo.Name = "Priority";
dgvCombo.Width = 300;
dgvCombo.DataSource = new string[] { "One", "Two", "Three" };
myDataGridView.Columns.Add(dgvCombo);
DataGridViewCheckBoxColumn dgvCheck = new DataGridViewCheckBoxColumn(true);
myDataGridView.Columns.Add(dgvCheck);
var row = new object[] { "One", false };
myDataGridView.Rows.Add(row);
row = new object[] { "Two", true };
myDataGridView.Rows.Add(row);
这篇关于如何在windows窗体中的datagridview中显示组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!