Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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();
        }
Posted
Updated 24-Mar-17 22:07pm

1 solution

Something like this:
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);
 
Share this answer
 
Comments
RickZeeland 29-Mar-17 13:02pm    
And ? did you give up or loose interest ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900