Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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?!?!
 
[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 4-Mar-10 23:16pm
Programm3r11.3K
Edited 7-Mar-10 19:18pm
v3
Rate this: bad
good
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++)
        col.Items.Add(i.ToString());
 
}
 
row.Cells["Number"].Value = "1";
  Permalink  
Comments
apprabhu at 7-Dec-12 23:36pm
   
It's really helped, Thanks.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

for sovle this problem,handle the DataError event datagrid .
  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
ver0776 at 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 at 10-Jul-13 17:46pm
   
i awesome that horrible and stupid response was the solution for me :D. thanks Kschuler
ver0776 at 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 at 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 at 10-Jul-13 17:30pm
   
wow, i only can say that it works!!!! thanks :D have a good day
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

private void ctrldataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
       {
//do nothing
       }
  Permalink  
Comments
Tim Corey at 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
good
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
  Permalink  

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

  Print Answers RSS
0 CPallini 235
1 DamithSL 225
2 OriginalGriff 198
3 George Jonsson 170
4 Maciej Los 165
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2014
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