StrataFrame Forum

Problem with DataGridView and a combobox column

http://forum.strataframe.net/Topic5036.aspx

By Greg McGuffey - 12/6/2006

Oh, I'm having fun now....



I have a form with a datagridview. It is a master-child sort a deal, with the master hooked up to a BO and the datagridview hooked up to a child BO via a businessbindingsource. The grid has a combo in it. As long as there is data in the binding source and the grid is on a row with data, all is good.



However, if Click on the new row or use bo.Add() in code or navigate to a master record with no children, then I get a TON of errors, all saying that "DataGridViewComboboxCell value is not valid". I must be doing something wrong here. I've loaded the combo with a data table, set the DisplayMember and ValueMember, all of which works fine, as long as there is data from the DGV datasource in the row. What am I missing?
By StrataFrame Team - 12/7/2006

When you add a new record to the business object, the combo box attempts to refresh to the value of the field behind the combo box, which is most likely a 0 or an empty string.  So, when it refreshes to this value, if the value does not exist within the combo box, the combo box throws up because there is no such value for it to select.  That's why we created the TopMostItem on our combo box, because if the value didn't exist, then it would throw errors when the data was pushed to the control.  So, after you build the data table for the combo box, add an extra row to it that has a value of String.Empty or 0, or whatever the value is within your new row, and you'll be good.
By Greg McGuffey - 12/7/2006

Cool. Thanks! I like when it starts making senseHehe