Combobox's behavior in dataGridView
I have added a combobox column to thedataGridView control. However, when I choose something from the combobox and leave the cell, the selected value gets disappeared: the item changes to blank. I haven't written any code in any of the events.
How can I make the selected values stay in the grid?
privatevoid AddComboBoxColumns(int pInt_InsertAfterColumn){
DataGridViewComboBoxColumn comboboxColumn =newDataGridViewComboBoxColumn();comboboxColumn.HeaderText =
"Action";comboboxColumn.Items.Add(
"In");comboboxColumn.Items.Add(
"Out");this.dataGridView1.Columns.Insert(pInt_InsertAfterColumn, comboboxColumn);}
[1409 byte] By [
RKBNAIR] at [2007-12-17]
Can you provide more details on this? I tried your code and I didn't have any problem with the values I select in the combo box cell being persisted. If you can provide specific steps that you do it will help.thanks,
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
Sure.
I have populated mydataGridView by saying dataGridView1.datasource=northwindDS
Then I added a combobox column programatically in the form_load event with 2 values "In" and "Out". However, I haven't set any datasource for this column.
At run-time, when I choose a value in the combobox in any of the rows, and tab to the next cell, the combobox reinitialize to blank.
Please let me know if you need me to post the entire code here.
Thanks again.
I am having the same problems with the DataGridViewComboBoxColumn,
In normal case, If i choose the value manually from the dropdown, the value will be persisted
However, If i double click on a empty DataGridViewComboBoxColumn, by default it will auto "select" the first item in the dropdown for me, anyway, if i move away from the combobox, the value will be lost.
I tried to trap the value, EditedFormattedValue, and FormattedValue in CellValueChanged Event Handler, but they are all empty.
Similiarly, i also find out that in second case, CurrentCellDirtyStateChanged event is not being fired at all.
Anyone has any solution or workaround? Thanks.