954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

DataGridView ComboBox Problem

I have a DataGridView containing information of cities of the world. User can retreive records and insert record of cities from DataGridView. Since every city is associated with a country, therefore in order to insert a new city user must insert country information too.

For this purpose, i have created four columns in DataGridView dynamically:
1 - S.No.
2 - Country(combo box)
3 - City Code (Edit Box)
4 - City Name (Edit box)

I have created the 'Country' column using "DataGridViewComboBoxColumn" class and populated it with DataTable using DataSource property, and hence the DisplayMember is 'Country_Name' and ValueMember is 'Country_Code' and it is working fine at the moment. Whenever user wants to add a new city, obviously user has to select the country too which i have provided in combobox.

Now the problem is on retreiving data. I am populating the Grid manually i.e. looping row by row and inserting into each cell from a DataSet which is again working fine for all columns EXCEPT the Country column in grid. The program gives me an exception repeatedly stating that "System.ArgumentException: DataGridViewComboBoxCell value is not valid.". I am trying to populate the Country column cell with the 'Country_Code' hoping to get the 'Country_Name' as the 'country_name' is the ValueMember BUT so far it is not letting me do that.

Kindly help me out with this problem, ill be thankful to you.

nomee919
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: