I have a combo box in my data grid view. I used datgridviewcolumn then add its properties. I need to know how to retrieve its selected item. Since I code the creation of my datagridviewcombobox. I can't create a event for selectedindexchanged for my combobox, it's property handler provides the dispose class. Help please!
Here is my code:
WithEvents cmb As New DataGridViewComboBoxColumn
salesOrderDatagrid.Columns.Add(
"Product ID", "Product ID")
updateDropdown()
cmb.HeaderText =
"Product Name"
cmb.Name =
"Product Name"
salesOrderDatagrid.Columns.Add(cmb)
salesOrderDatagrid.Columns.Add(
"Unit Price", "Unit Price")
salesOrderDatagrid.Columns.Add(
"Quantity", "Quantity")
salesOrderDatagrid.Columns.Add(
"Sub Total", "Sub Total")
salesOrderDatagrid.Columns(
"Product ID").DisplayIndex = 0
salesOrderDatagrid.Columns(
"Product Name").DisplayIndex = 1
salesOrderDatagrid.Columns(
"Unit Price").DisplayIndex = 2
salesOrderDatagrid.Columns("Quantity").DisplayIndex = 3
salesOrderDatagrid.Columns(
"Sub Total").DisplayIndex = 4
Dim i As Integer
For i = 0 To 4 Step 1
salesOrderDatagrid.Columns(i).Width = 144
Next
db.DBConnect2(cn)
Dim selectString As String = "SELECT * FROM tblProducts"
Dim dscmd As New SqlDataAdapter(selectString, cn)
Dim prodName As New DataSet()
dscmd.Fill(prodName,
"Product_Name")
cn.Close()
Dim dt As DataTable = prodName.Tables.Item("Product_Name")
Dim rowCateg As DataRow
For Each rowCateg In dt.Rows
cmb.Items.Add(rowCateg.Item(
"Product_Name"))
Next
Here is my code:
WithEvents cmb As New DataGridViewComboBoxColumn
salesOrderDatagrid.Columns.Add(
"Product ID", "Product ID")
updateDropdown()
cmb.HeaderText =
"Product Name"
cmb.Name =
"Product Name"
salesOrderDatagrid.Columns.Add(cmb)
salesOrderDatagrid.Columns.Add(
"Unit Price", "Unit Price")
salesOrderDatagrid.Columns.Add(
"Quantity", "Quantity")
salesOrderDatagrid.Columns.Add(
"Sub Total", "Sub Total")
salesOrderDatagrid.Columns(
"Product ID").DisplayIndex = 0
salesOrderDatagrid.Columns(
"Product Name").DisplayIndex = 1
salesOrderDatagrid.Columns(
"Unit Price").DisplayIndex = 2
salesOrderDatagrid.Columns("Quantity").DisplayIndex = 3
salesOrderDatagrid.Columns(
"Sub Total").DisplayIndex = 4
Dim i As Integer
For i = 0 To 4 Step 1
salesOrderDatagrid.Columns(i).Width = 144
Next
db.DBConnect2(cn)
Dim selectString As String = "SELECT * FROM tblProducts"
Dim dscmd As New SqlDataAdapter(selectString, cn)
Dim prodName As New DataSet()
dscmd.Fill(prodName,
"Product_Name")
cn.Close()
Dim dt As DataTable = prodName.Tables.Item("Product_Name")
Dim rowCateg As DataRow
For Each rowCateg In dt.Rows
cmb.Items.Add(rowCateg.Item(
"Product_Name"))
Next
Last edited: