Combobox in DataGridView - How to Populate?

wabs27

Member
Joined
Jul 31, 2006
Messages
11
Programming Experience
5-10
Hi,

I have a datagridview that is getting it's datasource from a dataset (which was populated from a stored procedure).

The datagridview holds information about products such as ProductName, ModelNumber, Price, Vendor, Category, etc. I have the datagridview columns being generated automatically. But now I decided that I want to change some of the fields such as Vendor and Category to be a drop-down (combobox) for editing purposes. (By the way - in design view the datragrid is not bound - it is only bound programmatically - is that the proper way to bind it?)

So now I am having a hard time trying to figure out how to change the textbox field to a combobox since it is being generated automatically. I figure that I need to change the datagridview not to generate columns automatically (and for some reason I don't even see that property in design view any more - where is it?). And then my question is how to populate the data into the datagrid? Will it be populated automatically if the column name matches the field name from the dataset if I set the datasource attribute to the dataset? Or is there something else that needs to be done? Then how do I have the Vendor combobox automatically selected to the value for this record from the database and how do I get all other records into the combobox.

I figured populating the combobox would look something like this but it's more complicated:

VB.NET:
Dim VendorColumn As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn
VendorColumn.DataSource = rSet2.Tables("VendorGrid")
VendorColumn.DisplayMember = "VendorName"
VendorColumn.ValueMember = "VendorCode"

Any help would be greatly appreciated.

Thank you.
 
Top Bottom