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?
private
void 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]
# 1

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"

MarkRideout at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2
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.

RKBNAIR at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3

Ok. What is occurring is that you have a mix of bound and unbound columns. The two combo box columns you add in the Form_load event isn't bound to any fields in the database. These unbound columns do not store their values when there is bound columns. Check out section 4.4.4 Mixed mode - Bound and unbound in the DataGridView FAQ (http://www.windowsforms.net/Samples/Go%20To%20Market/DataGridView/DataGridView%20FAQ.doc)

Basically you are responsible for storing values for columns that are unbound when you have bound columns.

There is also a sample in the DataGridView samples collection (http://www.windowsforms.net/Samples/download.aspx?PageId=1&ItemId=216&tabindex=4) that shows having a unbound checkbox column along with databound columns.

Hope this helps,
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"

MarkRideout at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 4

Hi,

I'm facing the same problem that the selection in DGVComboboxColumn doesn't persist. I checked the FAQ 4.4.4 but can't find any code snippet to solve this problem. Do you have any more hints?

Thanks

PeterPeter at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 5

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.

jeffo at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...