locked
DataGridView Combo Box Cell value is not valid RRS feed

  • Question

  • I have a dataset comprising two tables. Table1 includes a foriegn key, which corrresponds to the primary key in Table2. I display Table1 with a DataGridView control. All is well if I use the default "TextBox" column type throughout.

    But I want to display the "description" value corresponding to the foriegn key from Table2. I tried to do this by adding a new column to the DataGridView with
             columntype = DataGridViewComboBoxColumn
             datasource = Table2BindingSource
             displaymember = description
             valuemember = primarykey

    This appears to work, until I close the form. Then I get repeated instances of "DataGridView Combo Box Cell value is not valid", one for each row, four times. This happens whether or not I have added/changed any data.

    Both Table1 foriegnkey and Table2 primarykey have type System.Int32.

    Can anyone help resolve this?

    Thanks--Mable

    Friday, February 3, 2006 5:06 AM

Answers

  • Mable,

     

    I manage to recreate your scenario. I feel that the foreignkey name in your table 1 is not same as the primarykey name in table2.

    So for the datapropertyname - pl set it to the exact column name of your foreign key of table 1.

     

    I recreated your scenario using 2 tables - emp (empid, empname, Emp_dept) and dept(deptid, deptname)

    where emp_dept is a foreign key and references deptid, datatype is integer in both cases.

    empbindingsource - datasource=dataset, datamember =emp

    deptbindingsource- datasource=dataset, datamember = dept

    datagridview.datasource = empbinding source

    add a comboboxcolumn with header "Department" to the datagridview

    set it as follows:

    datapropertyname= Emp_dept

    datasource = deptbindingsource

    displaymember = deptname

    valuemember= deptid

    it works this way.

    regards

     

     

     

    rgds

     

    Monday, February 6, 2006 4:17 AM

All replies

  • Can anyone help with this? I've read the FAQ, but I cannot find this problem addressed.

    The context of the error is "formatting or sizing the cell". It occurs sometime between form_closed and form_disposed.

    --Mable

    Sunday, February 5, 2006 3:47 AM
  • Try setting the datapropertyname = PrimaryKey

    Meaning if your primarykey column is Emp_ID, then datapropertyname = Emp_ID

    Cheers

    Sunday, February 5, 2006 8:03 AM
  • Yes, I tried this. It is how I get the error.

    If I leave dataproperyname set to <none>, I don't get an error, but the column loses its association with my table, and is not useful.

    I'm guessing it is a data type issue, or maybe you just cannot use a combobox column in the way I'm trying to use it.

    --Mable

    Monday, February 6, 2006 3:34 AM
  • Mable,

     

    I manage to recreate your scenario. I feel that the foreignkey name in your table 1 is not same as the primarykey name in table2.

    So for the datapropertyname - pl set it to the exact column name of your foreign key of table 1.

     

    I recreated your scenario using 2 tables - emp (empid, empname, Emp_dept) and dept(deptid, deptname)

    where emp_dept is a foreign key and references deptid, datatype is integer in both cases.

    empbindingsource - datasource=dataset, datamember =emp

    deptbindingsource- datasource=dataset, datamember = dept

    datagridview.datasource = empbinding source

    add a comboboxcolumn with header "Department" to the datagridview

    set it as follows:

    datapropertyname= Emp_dept

    datasource = deptbindingsource

    displaymember = deptname

    valuemember= deptid

    it works this way.

    regards

     

     

     

    rgds

     

    Monday, February 6, 2006 4:17 AM
  • dsani--

    Thank you! I created a new project, just as you outlined. It works fine. Now I must figure out what I did differently in my original project. At least now I know it works.

    --Mable

    Monday, February 6, 2006 7:22 PM
  • I had the exact same problem, the weird thing is that all I did was that I deleted the datagridview and created a new one, Hey presto, it works!

    And the column names for the Primary Key and foreign key being used are different.
    DataPropertyName was set to none.
    Monday, December 7, 2009 12:54 PM
  • I had the same problem.

    In my case the solution was to fill the data adapter of the Foreign key table. This was not being automatically filled and this was the cause of the problem.

    In the Page_Load Event:


    Me.TblUserTypesTableAdapter.Fill(Me.DonateDataSet.tblUserTypes)

     

    Regards Mark Jarzebowski

    • Proposed as answer by GLOBusa Sunday, April 10, 2011 9:32 AM
    • Unproposed as answer by GLOBusa Sunday, April 10, 2011 9:32 AM
    Sunday, October 24, 2010 2:11 AM
  • Hello everybody!

    I assume most of you are tired of looking for the solution as I am...

    I did found one...

    Make the datagridview control invisble when the form is closing (adding simple code in form closing event "me.datagridviewX.visible=False").

    So you will not get this annoying error message and the datagridview still functions well until the form is cloded.

    Enjoy!

    David G.

     

    • Proposed as answer by GLOBusa Sunday, April 10, 2011 9:32 AM
    Sunday, April 10, 2011 9:32 AM
  • Whew, thanks for this David. I've just wasted a day on this Visual Studio bug which seems to have been around forever according to other postings I have seen.
    Retired VB programmer
    Friday, June 10, 2011 4:39 AM
  • I may have an addition to the above topic.

    In my case the error only occurs if I set the combo boxes to automatically expand in width based on the cell contents! I changed this to a fixed column width and the problem goes away.

    Hope this helps.

    • Proposed as answer by Voulpan Thursday, September 1, 2011 9:43 AM
    • Unproposed as answer by Voulpan Thursday, September 1, 2011 9:43 AM
    Thursday, September 1, 2011 9:43 AM