I know that in a normal ComboBox
, if the FlatStyle
is Standard
, the user will be able to type a value that is not in the Items
list. But if a combo box in a DataGridView
is Standard
, it won't let me type a new value. Is it possible to achieve this functionality in a column in a DataGridView
?
Asked
Active
Viewed 461 times
4

Peter Mortensen
- 30,738
- 21
- 105
- 131

Juan
- 15,274
- 23
- 105
- 187
-
You may want to take a look at using the DataRepeater control. The DataGridView control seems to be designed for viewing data. If you want the users to control the data then the DataRepeater is probably the way you want to go. – Nick Jun 07 '11 at 14:47
-
possible duplicate of [How to change cell's ComboBox style in DataGridViewComboBoxColumn](http://stackoverflow.com/questions/202084/how-to-change-cells-combobox-style-in-datagridviewcomboboxcolumn) – Jay Riggs Jun 07 '11 at 15:05
2 Answers
1
Well, in a DataGridView, you can add a column of DataGridViewComboBoxColumn
type. It's DisplayStyle
and/or FlatStyle
are dependent on the current row state. I think when you add a new row (edit mode), you are able to add values to it.
References: Add items to DataGridViewComboBoxColumn in DataGridView during runtime http://www.lazycoder.com/weblog/2006/09/12/adding-values-to-the-datagridviewcomboboxcell-at-runtime/

Community
- 1
- 1

DoomerDGR8
- 4,840
- 6
- 43
- 91
0
private void dataGridView2_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
try
{
switch (dataGrid_ItemsList.Columns[dataGrid_ItemsList.SelectedCells[0].ColumnIndex].HeaderText)
{
case "Batch":
if (e.Control is ComboBox)
{
ComboBox _with1 = (ComboBox)e.Control;
_with1.DropDownStyle = ComboBoxStyle.DropDown;
_with1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
_with1.AutoCompleteSource = AutoCompleteSource.CustomSource;
_with1.AutoCompleteCustomSource = BatchList;
//_with1.Validating -= HandleComboBoxValidating;
//_with1.Validating += HandleComboBoxValidating;
_with1.Validating += (ss, ee) =>
{
if (!_with1.Items.Contains(_with1.Text))
{
var comboColumn = dataGrid_ItemsList.CurrentCell as DataGridViewComboBoxCell;
_with1.Items.Add(_with1.Text);
_with1.Text = _with1.Text;
comboColumn.Items.Add(_with1.Text);
this.dataGrid_ItemsList.CurrentCell.Value = _with1.Text;
}
};
}
break;
}
}
catch (Exception ex)
{
_CommonClasses._Cls_ExceptionsHandler.HandleException(ex,false);
}
}

sandipmatsagar
- 35
- 2