Hiya peeps!

I have a DataGridView added to my windows form application form. Some of the columns are DataGridViewComboBoxColumn columns.

I would like to populate the column combo-boxes from members of objects that are in a list. I previously had this working just fine in a test implementation by setting the data source of the column to the list and setting the DataPropertyName of the column to a string of the name of the relevant member.

I've changed this implementation now to use a list of a slightly more complex type of object, the list is now a member of another object. However now the ComboBox is populated by the name of the list objects class and upon selection gives an error dialog for:

"System.ArgumentException: DataGridViewComboBoxCell value is not valid."

Which figures because the name of the class is obviously not what is listed in the data members string.

Eg. A class is called baritem, objects of this type are listed on a BindingList(Of baritem) named bar, which is a member within the foo class:

vb Code:
  1. Public Class baritem
  2.         Public Property peanuts As String
  3.     End Class
  4.     Public Class foo
  5.         Public Property bar As BindingList(Of baritem)
  6.     End Class

I declare a foo type object and add some data for a single item on the list:

vb Code:
  1. Dim foobar As foo = New foo() With { _
  2.         .bar = New BindingList(Of baritem) From { _
  3.             New baritem() With { _
  4.                 .peanuts = New String("dodgy") _
  5.             } _
  6.         } _
  7.     }

Then in the forms OnLoad event handler I setup the data binding to one of the columns in the DataGridView. The grid has a column named Description that should match up to the peanuts member of the listed baritem object:

VB Code:
  1. ProfileDataGridView.AutoGenerateColumns = False
  2.    
  3.     Dim gdvcbc As DataGridViewComboBoxColumn = ProfileDataGridView.Columns("Description")
  4.     gdvcbc.DataSource = foobar.bar
  5.     gdvcbc.DataPropertyName = "peanuts"

This all runs without exception (It's in a Try Catch) and the form displays. Clicking on the ComboBox dropdown displays "ProfileMaker.ProfileMaker+baritem" instead of the expected "dodgy". On selecting this item and confirming the selection the error as outlined appears.

I tried adding Dim baritemlist As new BindingList(Of baritem) = foobar.bar and binding to that reference instead but with no change in the result.

The error is particularly annoying because it seems to be saying: "Yo, we heard you like strings in your ComboBoxes so we put a string in the ComboBox that's not in the list you provided and now we're gonna complain that it's not in the list you provided. Go fixthat, code monkey!".

A) How the flip is it even getting the class name as a string?!?
B) How can I fix it?
C) How many more times can I think I've finally gotten the hang of this VB lark to find another stinking pile of badly-documented illogicaly-behavioured dog's doo of a control that sets me back an entire day without putting my fist through the screen?