nomee919 0 Newbie Poster

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.