randys106
asked on
Trouble with Binding Source
I have an application which accesses a database consisting of one table (Customers) with two fields (LastName and FirstName). I drug the data source onto my form which automatically generated a data set, binding source, table adapter, table adapter manager, and a binding navigator. (I do not pretend to fully understand what each of these does). This automatically generated text boxes for FirstName and LastName.
I want to load the data into an unbound listbox.
This code works:
My listbox fills with last and first names.
But, if I change the visible property of the textboxes to False, the listbox fills with commas.
I do not need the textboxes to be present except to make the above code work.
Is there some way to get the data directly from the Binding Source (or Table Adapter or Binding Navigator, etc.)?
Thanks
I want to load the data into an unbound listbox.
This code works:
Me.CustomersBindingSource.MoveFirst()
For i = 1 To CustomersBindingSource.Count
ListBox1.Items.Add(Me.LastNameTextBox.Text + ", " + Me.FirstNameTextBox.Text)
Me.CustomersBindingSource.MoveNext()
Next
My listbox fills with last and first names.
But, if I change the visible property of the textboxes to False, the listbox fills with commas.
I do not need the textboxes to be present except to make the above code work.
Is there some way to get the data directly from the Binding Source (or Table Adapter or Binding Navigator, etc.)?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Randy,
Also try this:
Adjust WSCGSoftwareDataSet, LastName, and ID to whatever you are having
The advantage of this will be use of:
To give you the value of ID upon click on the list box.
Also try this:
Adjust WSCGSoftwareDataSet, LastName, and ID to whatever you are having
ListBox1.DataSource = WSCGSoftwareDataSet.Tables(0)
ListBox1.DisplayMember = "LastName"
ListBox1.ValueMember = "ID"
The advantage of this will be use of:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.SelectedIndex > -1 Then
MessageBox.Show(ListBox1.SelectedValue.ToString())
End If
End Sub
To give you the value of ID upon click on the list box.
ASKER