Problems with bound list source for DataGridViewComboBoxColumn
-
I have a data application that is using a DataSet via the designer. I'm trying to create a form that binds data from one table "MyData". One of the fields "picker_fk" uses an FK relationship to a second table "Picker". "Picker" has only one field in it called "descript" (not null, unique). In the form, I set up the DataGridView to use the DataSet.MyData table. For the combo box column, I set the following properties: DataPropertyName = "picker_fk" DataSource = bndPicker (a binding source that uses the "Picker" table from the DataSet) DisplayMember = "descript" ValueMember = "descript" This is all good until I create a new row, select a value from the combo box, and then move focus away. I get a message: SystemArgumentException: Column "descript" is not belong to table "Picker". What's up with that? I'm looking right at the field in the DataSetDesigner. "descript" is the ONE AND ONLY field in "Picker". How can the debugger say it's not in there? I dug around and found a suggestion that this error could occur with data type mismatches. But I have verified that both Picker.descript and the referencing MyData.picker_fk are both of type System.String. Does anyone have any ideas?
-
I have a data application that is using a DataSet via the designer. I'm trying to create a form that binds data from one table "MyData". One of the fields "picker_fk" uses an FK relationship to a second table "Picker". "Picker" has only one field in it called "descript" (not null, unique). In the form, I set up the DataGridView to use the DataSet.MyData table. For the combo box column, I set the following properties: DataPropertyName = "picker_fk" DataSource = bndPicker (a binding source that uses the "Picker" table from the DataSet) DisplayMember = "descript" ValueMember = "descript" This is all good until I create a new row, select a value from the combo box, and then move focus away. I get a message: SystemArgumentException: Column "descript" is not belong to table "Picker". What's up with that? I'm looking right at the field in the DataSetDesigner. "descript" is the ONE AND ONLY field in "Picker". How can the debugger say it's not in there? I dug around and found a suggestion that this error could occur with data type mismatches. But I have verified that both Picker.descript and the referencing MyData.picker_fk are both of type System.String. Does anyone have any ideas?
Never mind. I found it. The error message is actually misleading because it doesn't have to do with the names. It has to do with the sequence in which databinding takes place. I set up the BindingSource for the grid BEFORE the BindingSource for the ComboBox options. It's odd that this error was not detected right away but only after adding a row, but I'm not the only one to experience this: http://adamhouldsworth.blogspot.com/2009_04_01_archive.html[^] (Scroll down to the 7 April 2009 entry "Data Binding Pitfall").