Link to home
Start Free TrialLog in
Avatar of mwalsh2000
mwalsh2000

asked on

Listbox

I have form1 which has a button which allows a user to lookup a customer name.  The button, when clicked opens another form (form2) which contains a listbox and the customer names are listed in the listbox bounded from a datasource (sql table).  I would like the user to be able to select an item in the listbox (by highlighting it) and clicking the select button at the bottom of the form2 and then have the item display in a text box on form1.  I am trying the following code to accomplish this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click

        form1.tbItemNmbr.Text = Me.lbItems.SelectedItem.ToString
       
    End Sub

The code displays "System.Data.DataRowView" in the text box not the customer name as desired.  Can someone point me in the right direction on this?
Avatar of vadim63
vadim63
Flag of United States of America image

You have to set    Me.ListBox1.ValueMember = "Customer Name" and then use:

form1.tbItemNmbr.Text = Me.lbItems.SelectedValue
ASKER CERTIFIED SOLUTION
Avatar of vadim63
vadim63
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mwalsh2000
mwalsh2000

ASKER

That got it, thanks!