Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trouble with Binding Source

Posted on 2014-12-28
3
Medium Priority
?
107 Views
Last Modified: 2014-12-29
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:
    
        Me.CustomersBindingSource.MoveFirst()
        For i = 1 To CustomersBindingSource.Count
            ListBox1.Items.Add(Me.LastNameTextBox.Text + ", " + Me.FirstNameTextBox.Text)
            Me.CustomersBindingSource.MoveNext()
        Next

Open in new window


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
0
Comment
Question by:randys106
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 2000 total points
ID: 40521544
I just tested the following code and it works as described below. Please apply the changes noted below to work in your project:
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        For Each r In WSCGSoftwareDataSet.Tables(0).Rows
            ListBox1.Items.Add(r(1))
        Next

    End Sub

Open in new window


WSCGSoftwareDataSet used here is my dataset name which is the same as WSCGSoftwareDataSet.xsd file in object browser, change it to whatever you have.

r(1) is the column index in your table. For now proceed with a single column (ex. firstname). But then use:

ListBox1.Items.Add(r(2) & ", " & r(1))

if Last Name has index 2 and First Name has index 1.

I have Button1_Click to run this code. You can put in form load if you wish.
0
 

Author Closing Comment

by:randys106
ID: 40521793
Perfect solution.  Thanks so much.
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40523057
Hi Randy,

Also try this:

Adjust WSCGSoftwareDataSet, LastName, and ID to whatever you are having
       ListBox1.DataSource = WSCGSoftwareDataSet.Tables(0) 

        ListBox1.DisplayMember = "LastName"
        ListBox1.ValueMember = "ID"

Open in new window


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

Open in new window


To give you the value of ID upon click on the list box.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question