Results 1 to 5 of 5

Thread: DataGridView ComboBox Problem

  1. #1
    nomee919 is offline C# Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2012
    Posts
    1
    Rep Power
    0

    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 in Grid 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 of 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.

  2. #2
    mcrkl is offline C# Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0
    Hello

    you can easily solve your problem just visit this tutorial page and look for what you need.
    there are many tutorials relate to .net grid with code.
    Dapfor .Net Grid Tutorial

  3. #3
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    701
    Rep Power
    61
    Quote Originally Posted by mcrkl View Post
    Hello

    you can easily solve your problem just visit this tutorial page and look for what you need.
    there are many tutorials relate to .net grid with code.
    Dapfor .Net Grid Tutorial
    Given that that doesn't relate to the DataGridView, I'm not sure it's relevant.

    Don't populate the grid manually. Use data-binding. Bind one table to the combo box column and the other table to the grid.

  4. #4
    AnnieCalvert is offline C# Forum Newbie
    .NET Framework
    .NET 1.1
    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0
    Sounds like you want the changes to be committed as soon as the user changes the drop down box, without them having to click off of the cell. In order to do this you will need to force the commit when the change happens using commit.edit. Then you could just listen for the Cell Value Changed and avoid having to try and register for the Combo Box Value Changed event on the underlying editing control.
    .Net Grid tutorial Part2: Data Binding

  5. #5
    annaharris is offline C# Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    May 2013
    Posts
    13
    Rep Power
    0
    Is there any other field involved within the datagridview that you are using for displaying all the fields.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking