468,771 Members | 1,921 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

Combo with different values in datagrid for different rows

bz
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
Feb 7 '08 #1
0 1103

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Kevin | last post: by
4 posts views Thread by Mike L | last post: by
3 posts views Thread by Doug | last post: by
4 posts views Thread by Ziv Riezman | last post: by
6 posts views Thread by Sebastian Santacrice | last post: by
6 posts views Thread by Ron L | last post: by
4 posts views Thread by Jim Shaffer | last post: by
3 posts views Thread by Frustrated Developer via DotNetMonster.com | last post: by
7 posts views Thread by Ausclad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.