Hi,
I have a datagrid with two columns Region and City
Both have combo-boxes. City column is unbound
What I want is, when use select a region, to fill the combo for City
column with appropriate cities for that region
I did this with a code like this
private void dataGridView1_CellEnter(object sender,
DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 5) // when I step into city column
{
switch
((string)dataGridView1.Rows[e.RowIndex].Cells[1].Value) // this is
region column
{
case "NY":
this.City.Items.Clear();
this.City.Items.AddRange(
"New York",
"Alabama",
"Georgetown");
break;
case "WA":
this.City.Items.Clear();
this.City.Items.AddRange(
"Acapulco",
"Seattle");
break;
default:
this.City.Items.Clear();
this.City.Items.AddRange(
"No city available");
break;
}
}
}
But after I step in first row in column city (and the combo is
populated ok), when I move to city col in second row (where the combo
should be set to new values) app gives me the following error:
"System.ArgumentException: DataGridViewComboBoxCell valus is not
valid"
It seems this occurs everytime when I move to a row where the combo
needs to be populated with new values
How should I handle this?
Thanks