Populating a datagridview combobox column with subsonic & vb.net
Just like the header, I am trying to populate a combo box in a datagridview.
Here's what I have so far:
Dim lc As System.Web.UI.WebControls.ListItemCollection = _
DataAccess.Part.GetListItems()
dgvcboPart.DataSource = lc
' This is a standalone combo box and it works ok
cboTest.DataSource = lc
Any suggestions as to what I am missing?
Thanks Tony W
a source to share
First I suggest you bind your collection to the BindingSource and then add the BindingSource to the DataGridView (so you know the position)
But binding the ComboBoxCell should be pretty simple.
Let's say you have a tattCurrency title that contains two columns, Id and Name. You have to bind this to your column (I suppose column 0 ist for your DataGridViewColumn)
dgvcboPart.Columns(0).DataSource = tblCurrency
dgvcboPart.Columns(0).ValueMember = "Id"
dgvcboPart.Columns(0).DisplayMember = "Name"
Then you can set the DataPropertyName on Property to your DataSource.
dgvcboPart.Columns(0).DataPropertyName = "Currency_Id"
Be carful, tblCurrency.Id and Currency_Id must be of the same type (Int32 and UInt32 don't work) And you get a nasty MessageBox with a full StackTrace if Currency_Id has a value that is not in tblCurrency (so you have to handle the DataError event)
a source to share