G
Guest
I have a DataGridView on my Windows form with one ComboBox column. I have set
the ComboBox to use the DropDown style, through the EditingControlShowing
event handler:
private void dgvSentences_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cbo = e.Control as ComboBox;
if (cbo != null) cbo.DropDownStyle = ComboBoxStyle.DropDown;
}
And I have setup whatever the user has typed to be stored in the dropdown
list through the CellValidating event handler:
private void dgvSentences_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
object eFV = e.FormattedValue;
DataGridViewComboBoxCell cbc = dgvSentences.CurrentCell as
DataGridViewComboBoxCell;
if (cbc != null && !cbc.Items.Contains(eFV))
{
cbc.Items.Insert(0, eFV);
if (dgvSentences.IsCurrentCellDirty)
dgvSentences.CommitEdit(DataGridViewDataErrorContexts.Commit);
cbc.Value = cbc.Items[0];
}
}
This parts works fine. What I would like to do is have a new row added at
the end of the list as soon as a user starts typing text into the cell, like
a DataGridViewTextBoxCell would do. If I choose an item from the DropDown
list, it will automatically create the new row. If I start typing in the
ComboBox cell, it does not create a new row for me to start a new entry. How
would I handle this?
the ComboBox to use the DropDown style, through the EditingControlShowing
event handler:
private void dgvSentences_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cbo = e.Control as ComboBox;
if (cbo != null) cbo.DropDownStyle = ComboBoxStyle.DropDown;
}
And I have setup whatever the user has typed to be stored in the dropdown
list through the CellValidating event handler:
private void dgvSentences_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
object eFV = e.FormattedValue;
DataGridViewComboBoxCell cbc = dgvSentences.CurrentCell as
DataGridViewComboBoxCell;
if (cbc != null && !cbc.Items.Contains(eFV))
{
cbc.Items.Insert(0, eFV);
if (dgvSentences.IsCurrentCellDirty)
dgvSentences.CommitEdit(DataGridViewDataErrorContexts.Commit);
cbc.Value = cbc.Items[0];
}
}
This parts works fine. What I would like to do is have a new row added at
the end of the list as soon as a user starts typing text into the cell, like
a DataGridViewTextBoxCell would do. If I choose an item from the DropDown
list, it will automatically create the new row. If I start typing in the
ComboBox cell, it does not create a new row for me to start a new entry. How
would I handle this?