Question copy selected item from combo box to string where datasource of combo box dataset

Rahul B

New member
Joined
Aug 10, 2010
Messages
1
Programming Experience
Beginner
Hi I have a form with a combo box called cmbSupplier. I want to select the name of the suppliers from a database table for and show it in the combo box as a drop down list. For doing so, I am susing the following code which work.


Private Sub frmPatentMaster_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim setting As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("Getin")

Dim constring = setting.ConnectionString.ToString()

Dim constrg As String




constrg = constring + "user id = " + Me.loginID.ToString() + " ; password = " + Me.loginPwd.ToString()

Dim mycon As New MySqlConnection(constrg)

'Open the connection and get a values from mst_supplier for populating the drop down list



Try

Dim SpCmd As MySqlCommand

SpCmd = New MySqlCommand("SP_SUPPLIER_DROPDOWN", mycon)

SpCmd.CommandType = CommandType.StoredProcedure

mycon.Open()

Dim myds As DataSet = New DataSet

Dim myadp As MySqlDataAdapter = New MySqlDataAdapter(SpCmd)

myadp.Fill(myds, "Mytable")

cmbSupplier.DataSource = myds.DefaultViewManager

cmbSupplier.DisplayMember = "Mytable.supplier" ' the stored procedure returns only one column called supplier






mycon.Close()

Catch ex As Exception

MessageBox.Show(ex.ToString)

Finally


mycon.Dispose()

End Try

End Sub



However, after that I am not able to copy the value of the selected item in the combo box to a string variable. The following code is not working



Private Sub cmbSupplier_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSupplier.SelectedIndexChanged


Dim SupplierName As String
SupplierName = Me.cmbSupplier.selectedItem.tostring
MessageBox.Show(SupplierName)

End Sub


The output of this shows the following info:
1. System.Data.DataViewManagerListItemTypeDescriptor but not the name of the supplier selected in the combo box. How Do I overcome it.






The output of this shows the following info:1. System.Data.DataViewManagerListItemTypeDescriptor but not the name of the supplier selected in the combo box. How Do I overcome it.
 
Back
Top