Click here to Skip to main content
15,881,752 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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:

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?!?!

[NEW]
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.
[NEW]

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

Many thanks in advance.
Kind regards,
Posted
Updated 7-Mar-10 18:18pm
v3

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.

C#
if (dgv.Columns["Number"].GetType() == typeof(DataGridViewComboBoxColumn))
{
    DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)dgv.Columns["Number"];
    for (int i = 0; i < 100; i++)
        col.Items.Add(i.ToString());

}

row.Cells["Number"].Value = "1";
 
Share this answer
 
Comments
apprabhu 7-Dec-12 23:36pm    
It's really helped, Thanks.
for sovle this problem,handle the DataError event datagrid .
 
Share this answer
 
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.
 
Share this answer
 
Comments
resis 10-Jul-13 17:46pm    
i awesome that horrible and stupid response was the solution for me :D. thanks Kschuler
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? http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/88c3adee-ed2a-41ee-9407-c3314588e08a/

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
C#
private void ctrldataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
       {
//do nothing
       }
 
Share this answer
 
Comments
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.
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900