Hi,
I am struggling with the DataGridViewComboBoxColumn in a DataGridView. I am able to populate the ComboBox and add it to the DataGridView, so far so good.
When running the form the ComboBox in the Grid seems to be “invisible”, it is activated only after doubleclick on it (sometimes multiple doubleclicks before something happens). It looks to me as if the ComboBox isn’t initiated yet. I also did not find a way to set e.g. the first Item in the ComboBox.
Unfortunately I cannot find any sample/issue on this subject.
Please advices,
Regards,
Wim
Forgot to add that you can also set the DataGridViewComboBox column in the designer and assign the data source in code. No need to remove and re-add a different column. And you you may use the attached mixin to make all combobox cell display a drop down image mimicking the combobox. See image attached.
Put this in Themes/App.mixin.theme
{ "appearances": { "table-combobox-cell": { "inherit": "table-cell", "states": { "default": { "styles": { "backgroundImage": "combo-arrow", "backgroundSize": "20px", "backgroundPosition": [ "center", "right" ] } } } } } }
Thank you and sorry I forgot to post a sample. In any case your code works well after you set the DataPropertyName:
cc.DataPropertyName = “Country”
Without that it cannot bind to a data source field.
Hi Luca,
Here is an example from what I am trying to achieve….
Regards,
Wim
The DataGridViewComboBoxCell shows the correct value already. There are no comboboxes created in each cell, it’s not how the DataGridView works. The ComboBox is created in edit mode. If you send a small test case showing the problem it would help.
Thanks Luca, I now have a partial solution. The ComboBox is now shown in the DataGridView, that is nice. But in existing DataGridView records it is still NOT initalized with the field value. Assume we have a DataGridComboBox with Country values and the existing record contains the value “US”, than this not shown in the ComboBoxGridfield.
In the attachment you’ll find the form as created with Visual Webgui. In the various Combo’s as part of the DataGridView all values of existing records are shown.
So the question is: How do I manage that a Combo inside a DataGridView shows the actual value?
I am using VB2015 and cannot find any sample in this respect.
Regards,
Wim
The editor is not shown until the cell is in edit mode. You can initiate edit mode by typing, double clicking or entering the cell, see the EditMode property.
https://wisej.com/docs/2.1/html/P_Wisej_Web_DataGridView_EditMode.htm
https://stackoverflow.com/questions/1814423/datagridview-how-to-set-a-cell-in-editing-mode
Please login first to submit.