Monday, May 11, 2009

Code for How to Add Combobox Columns to datagridview in VB.Net

'Get a reference to the default DataView of the table
Dim dv As DataView = dt.DefaultView

'Create 2 combo box columns: Set DisplayMember, ValueMember and DataSource
Dim colQty1 As New DataGridViewComboBoxColumn
colQty1.DisplayMember = "Quantity1"
colQty1.ValueMember = "Quantity1"
colQty1.HeaderText = "Quantity 1"
colQty1.DataSource = dv

Dim colQty2 As New DataGridViewComboBoxColumn()
colQty2.DisplayMember = "Quantity2"
colQty2.ValueMember = "Quantity2"
colQty2.HeaderText = "Quantity 2"
colQty2.DataSource = dv

'Add both columns to it
dgv.Columns.AddRange(New DataGridViewColumn() {colQty1, colQty2})

No comments: