I'm having a problem when selecting cells in a DataGridViewComboBoxColumn. Each time a cell is selected I see the following error:
"DataGridView Default Error Dialog:
System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that you Main function has STAThreadAttribute marked on it. ..."
Firstly, I don't use any Main() methods in my application. I did try adding one with the suggested attribute, but it had no affect. Does anyone know what this means
Thanks,
Nate

DGVComboBoxColumn gives ThreadStateException
Dheerendra
In VB, double-click the "My Project" icon in the solution explorer and tell me if the "Enable application framework" check box is checked. If it is unchecked, check it and then set your Startup form value appropriately and see if that helps. < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
hYp3r57231
Yes - look like a hosting issue. Visual Studio creates a hosting environment around the application. Looks like there was some problems getting that installed. In the mean time you can also goto the project properties and in the Debugger tab uncheck the "Enable the Visual Studio hosting process" and this should be just the same as double-clicking your EXE.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
naaz911
I'm still seeing the DGVComboBoxColumn exception.
-Nate
Lana567890
I have a large application converted from VS '03 to '05 with many Forms and derived Forms, all of which are opened in one main MDI window via a MainMenu. It would be impossible to post code due to the size of the app. I created a sample application with the basic functionality and I don't see the exception.
As far a the Main() method goes, I don't include it in any of my Form classes. It seemed from the error message that I might need this method in at least the form with the ComboBoxColumn control. So I tried to add Main() with STAThreadAttribute, but this had no effect.
I noticed on the MSDN2 page for DGVComboBoxColumn that they included Main() for enabling Visual styles. I also have a problem where all of my controls are plain 3D boxes with no XP Styles. In the same sample application I tried for the above I see XP styleing applied. I didn't change any features, so I'm not sure why they aren't being drawn this way as well.
I'm not really sure where do go from here.
Thanks,
Nate
Rainz
-Nate
Thomas Logan
Check the callstack where you're getting this exception to see where you're currently calling into the DGV from using Debug->Windows->Callstack. If you're on the incorrect thread, you need to call DataGridView.Invoke or BeginInvoke to call that method.
SimonSa
After clicking OK for the error the ComboBox does show up and is available for use. But, the value set in the ComboBox does not match the Cells current value. The combobox's value starts with the first value in the list. And each cell that is clicked on after that the combobox value is the last selection made. The value of the combobox does not get updated to match the cells value.
-Nate
Dougins
Because it hasn't answered my problem yet and I don't want to deter other people from posting.
The CallStack is empty when this error occurs. This is not an area that i am doing anything programatically. When I manually click on a cell this error occurs. I don't understand what you mean for me to use DataGridView.Invoke for. Was this a reference to my problem with trying to use the Main() method in a Form
sacuza
If you can post some code or describe your application structure a bit it will help us identify what is going on. Also, when you say you don't have a main() I assume you are using VB If so, we can try some things out to create a custom main routine if need be.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
thanks,
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
Rob Hershfield
-Nate
dirtyKarl
Matthew Martin
Thanks,
Nate
J. Leite
Thanks,
Nate
Meffistas
It does sound as if there is a configuration issue going on here. What if you launch your application from the command line/explorer instead of inside of visual studio Just double-click the EXE. Same issue < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"