Problem with DataGridView and a combobox column


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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?
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Cool. Thanks! I like when it starts making senseHehe
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search