Click here to Skip to main content
12,072,809 members (70,961 online)
Rate this:
Please Sign up or sign in to vote.
See more: .NET3.5 C# Windows .NET , +
Hi all,

I properly know what you are thinking, just Google the topic, and to let you know I have done so.... But all the solutions lead up to the same problem.

I have tried the following solution, but with no luck (this is most of the solutions on the net):
I was getting an error dialog with the message
"System.Argument.Exception: DataGridViewComboBoxCell value is not valid" when
I had the AutoSizeColumnsMode property for the grid set to "AllCells" but the
problem went away when I set the value to "None". Simply opening the form and
then closing it would cause the error dialog to appear numerous times and the
text in some of the ComboBox cells would disappear.

So this is the strange thing, the datagridview is with in a tab control (tab page), but as soon as I remove the datagridview from the tab page and place it directly on the form, everything works Confused | :confused: Confused | :confused:

Further investigation show that when the datagridview is placed on a tab page that doesn't have the focus, and one navigates to that tab page is when the error occurs. If the datagridview is place on a tab page that has focus when the window shown, no error occurs?!?!

When I place the same datagridview outside the tab page control and directly onto the form, the whole datagridview control works, thus an item within the data source is being selected. I do not believe that the error is caused by data binding.

Why is this happening? Does anyone know how to fix this??

Many thanks in advance.
Kind regards,
Posted 4-Mar-10 23:16pm
Edited 7-Mar-10 19:18pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

If anyone is still looking (like I did)...

In my case, it was data type mismatch (even though I had int's, it was still treating them as strings) since DGV wasn't bound. My solution was to assing .ToString() on the objects in the combobox and during the assignment for default values.

if (dgv.Columns["Number"].GetType() == typeof(DataGridViewComboBoxColumn))
    DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)dgv.Columns["Number"];
    for (int i = 0; i < 100; i++)
row.Cells["Number"].Value = "1";
apprabhu 7-Dec-12 23:36pm
It's really helped, Thanks.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

for sovle this problem,handle the DataError event datagrid .
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You probably have your grid setup so that the DataGridViewComboBox column is bound with a DataSource and are trying to set the value in it to one that is not in the DataSource.   When loading the grid you should make sure that the value for that column is set to one that is in your DataSource.   Or you could add a value to the DataSource bound to the column.
ver0776 22-Jun-10 15:43pm
I spent 10 minutes looking up my account information just to say this is A horrible and stupid response. Did you even read his post???

I have the same issues without even databinding...
resis 10-Jul-13 17:46pm
i awesome that horrible and stupid response was the solution for me :D. thanks Kschuler
ver0776 22-Jun-10 15:44pm
Reason for my vote of 1
Lame, stupid an obvious answer that shows you did not even read his post.
Kschuler 22-Jun-10 16:00pm
Wow. I'm sorry your having a bad day and can't find a solution to your problem. I didn't think it was a horrible and stupid response to point out the need for the value to be valid when the error message is "Value is not valid." When you were searching for an answer did you find this thread?

It has some possible work arounds.
resis 10-Jul-13 17:30pm
wow, i only can say that it works!!!! thanks :D have a good day
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

private void ctrldataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
//do nothing
Tim Corey 22-Jun-12 21:56pm
Why are you attempting to answer a 2-year-old question now? The technologies, languages, and tools have all changed by now and I'm sure the OP has moved on by now.
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

For me DataGridViewComboBoxColumn class never worked properly in case if you like to change properties in run-time, such as DataSource, DisplayMember etc.

The solution which works for me at runtime is create a new DataGridViewComboBoxColumn with same properties, remove old one and just then insert into the new DataGridViewComboBoxColumn into Grids columns collection.
The conclusion is: never change DataGridViewComboBoxColumn properties, just replace it with newly created.
However there is still a problem: I am working mostly in multithreading apartments. Clicking on drop-down button raise and error:
"Current thread must be set to single thread apartment (STA) mode"
Again solution here is just trapping the exception on DataError event of the grid without any actions

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100