Help in datagridview combobox.

ljpv14

Active member
Joined
Nov 28, 2011
Messages
44
Programming Experience
3-5
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



 
Last edited:
What are you actually trying to achieve? Why do you need, or think you need, to get the SelectedItem? Normally you don't need to do anything because the SelectedValue of the embedded editing control and the Value of the cell are automatically passed back and forth as required. What are you trying to do that should require more than that?
 
I am after the value of the selected item in the combobox column. What I am trying to achieve is to retrieve the selected text from a certain combobox column. Can you kindly give me some solutions on how to retrieve the text from the combobox column in a datagridview?
 
You may think that you're providing a clear explanation but you're not. If you actually want the text from a cell then you use the FormattedValue property of that cell. If that's not what you want then you will have to provide the proper explanation that I asked for previously instead of just repeating what you have already posted.
 
Back
Top