I have a combo box with a list of my customers, when a user selects a customer i
have the customer code populate a label called LBcustomer.

here is how i populate my combo box

Dim connString As String = "Data Source=" & ServerV & ";Initial Catalog=" & databaseV & ";Persist Security Info=True;User ID=" & usernameV & ";Password=" & passwordV & ""
        Dim conn As New SqlConnection(connString)
        Dim strSQL As String = "Select Customer,Name From ArCustomer where Salesperson=" & Me.LBASM.Text & ""
        Dim DA As New SqlDataAdapter(strSQL, conn)
        Dim dt As New DataTable        'Populate the datatable     
        DA.Fill(dt)        'Bind the stock datatable to the combobox     
        With CBOCustomer
            .DropDownStyle = ComboBoxStyle.DropDownList
            .DataSource = dt
            .DisplayMember = "Name"
            .ValueMember = "Customer"

        End With

i also have

Private Sub CBOCustomer_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBOCustomer.SelectedIndexChanged
        Me.LBCustomer.Text = Me.CBOCustomer.SelectedValue.ToString
          End Sub

this populate the label, but when first run, the label says
"System.Data.datarowview"
(see the pic below)
when i use the combo and select a customer it then populates the customer code in the
label. it only does this the first time the code is run. how can i make this label blank or input a number I.E "0"?

Recommended Answers

Can you explain where will you be getting the customer code from? You want to make the customer code to appear once and then after that leave it blank?

Jump to Post

All 2 Replies

Can you explain where will you be getting the customer code from? You want to make the customer code to appear once and then after that leave it blank?

Member Avatar

Put your code in the SelectedValueChanged event instead of the SelectedIndexChanged event: since you are using the SelectedValue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.