A
aXqd
i want a editable comboboxcell for a datagridview, i have done these:
[dgvConfigShow is a DataGridView]
public partial class Form1 : Form
{
....
private static List<string> _tempList = new List<string>(new string[]
{});
....
private void lbTypes_SelectedIndexChanged(object sender, EventArgs e)
{
foreach(...)
{
int newRowIndex = dgvConfigShow.Rows.Add();
DataGridViewRow newRow = dgvConfigShow.Rows[newRowIndex];
DataGridViewCell dgvcellCategoryName =
newRow.Cells["dgvcolCategoryName"];
dgvcolCategoryName.DataSource = _tempList;
}
}
....
private void dgvConfigShow_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
DataGridViewComboBoxEditingControl comboControl = e.Control as
DataGridViewComboBoxEditingControl;
if (comboControl != null)
if (comboControl.DropDownStyle != ComboBoxStyle.DropDown)
comboControl.DropDownStyle = ComboBoxStyle.DropDown;
}
....
private void dgvConfigShow_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
DataGridViewComboBoxCell cell = dgvConfigShow.CurrentCell as
DataGridViewComboBoxCell;
if (cell == null) return;
string curVal = e.FormattedValue as string;
if (!String.IsNullOrEmpty(curVal) && !_tempList.Contains(curVal))
_tempList.Add(curVal);
cell.Value = curVal;
}
....
}
everything goes fine until i try this:
input "a" into row 1 <-> _tempList = ["a"]
input "b" into row 2 <-> _tempList = ["a", "b"]
input "a" into row 1 <-> _tempList = ["a", "b"]
input/select "b" on row 1 <-> _tempList = ["a", "b"] but meanwhile
raised the well-known exception (DataGridViewComboBoxCell: Value is
not valid)
any idea, please?
[dgvConfigShow is a DataGridView]
public partial class Form1 : Form
{
....
private static List<string> _tempList = new List<string>(new string[]
{});
....
private void lbTypes_SelectedIndexChanged(object sender, EventArgs e)
{
foreach(...)
{
int newRowIndex = dgvConfigShow.Rows.Add();
DataGridViewRow newRow = dgvConfigShow.Rows[newRowIndex];
DataGridViewCell dgvcellCategoryName =
newRow.Cells["dgvcolCategoryName"];
dgvcolCategoryName.DataSource = _tempList;
}
}
....
private void dgvConfigShow_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
DataGridViewComboBoxEditingControl comboControl = e.Control as
DataGridViewComboBoxEditingControl;
if (comboControl != null)
if (comboControl.DropDownStyle != ComboBoxStyle.DropDown)
comboControl.DropDownStyle = ComboBoxStyle.DropDown;
}
....
private void dgvConfigShow_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
DataGridViewComboBoxCell cell = dgvConfigShow.CurrentCell as
DataGridViewComboBoxCell;
if (cell == null) return;
string curVal = e.FormattedValue as string;
if (!String.IsNullOrEmpty(curVal) && !_tempList.Contains(curVal))
_tempList.Add(curVal);
cell.Value = curVal;
}
....
}
everything goes fine until i try this:
input "a" into row 1 <-> _tempList = ["a"]
input "b" into row 2 <-> _tempList = ["a", "b"]
input "a" into row 1 <-> _tempList = ["a", "b"]
input/select "b" on row 1 <-> _tempList = ["a", "b"] but meanwhile
raised the well-known exception (DataGridViewComboBoxCell: Value is
not valid)
any idea, please?