PC Review


Reply
Thread Tools Rate Thread

Combo with different values in datagrid for different rows

 
 
bz
Guest
Posts: n/a
 
      7th Feb 2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo with different values in datagrid for different rows bz Microsoft Dot NET Framework 0 7th Feb 2008 12:16 AM
DataGrid, Windows - Does not refresh. data is in the rows but they are not visible, the rows are solid blue Richard Microsoft C# .NET 1 2nd Sep 2005 01:56 PM
datagrid scrolling...capturihng rows displayed in view of datagrid Patrick Microsoft Dot NET Framework Forms 3 7th Jun 2004 11:07 AM
searching a datagrid's rows and displaying rows where item was found Angel Microsoft C# .NET 0 26th Apr 2004 05:51 PM
DataGrid Component | Displaying columns of a DataSet as Rows in a DataGrid ? Diego TERCERO Microsoft C# .NET 3 19th Dec 2003 02:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:53 PM.