hi there,

i had a question regarding this before as well.
i have a datagridview and it has three combo boxes, with one with form name and the other with employee name and the other just a selection. what i want to do is to make the form name combo box to be a datagridview combo box as well as a datagridview textbox .
the code is below

private void dgvForm_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            DataGridViewComboBoxEditingControl comboControl = e.Control as DataGridViewComboBoxEditingControl;
            if (comboControl != null)
                //Set the DropDown style to get an editable ComboBox
                if (comboControl.DropDownStyle != ComboBoxStyle.DropDown)
                    comboControl.DropDownStyle = ComboBoxStyle.DropDown;

                    int r = dgvForm.CurrentRow.Index;



private void dgvFrom_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
            DataGridViewComboBoxCell cell = dgvForm.CurrentCell as DataGridViewComboBoxCell;

            if (cell != null && !cell.Items.Contains(e.FormattedValue))
                // Insert the new value into position 0
                // in the item collection of the cell
                cell.Items.Insert(0, e.FormattedValue);
                // When setting the Value of the cell, the  
                // string is not shown until it has been
                // comitted. The code below will make sure 
                // it is committed directly.
                if (dgvForm.IsCurrentCellDirty)
                    // Ensure the inserted value will 
                    // be shown directly.
                    // First tell the DataGridView to commit 
                    // itself using the Commit context...
                // ...then set the Value that needs 
                // to be committed in order to be displayed directly.
                cell.Value = cell.Items[0];

but when i add this code all the combo box becomes datagridviewtextboxes when the datagridview combo box is being clicked..
how can i avoid this situation and make only the form name datagridview combobox a datagridview textbox

please can some one guide me thanxxxx

7 Years
Discussion Span
Last Post by judithSampathwa

Can you some me the code with which you create a dgv and its columns?

the data gridview is already created and the columns are defined, with three datagridview combo box columns, i wna tone datagridview combo box column to be acing as a datagridview text box column when the cell is being clicked


Try this:

this.dataGridView1["columnIndex", "rowIndex"] = new DataGridViewTextBoxCell();

is it instead of the below line

DataGridViewComboBoxCell cell = dgvForm.CurrentCell as DataGridViewComboBoxCell;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.