www.webdeveloper.com
Results 1 to 3 of 3

Thread: Listbox1 to Listbox2

  1. #1
    Join Date
    Jul 2004
    Posts
    61

    Listbox1 to Listbox2

    How would I take results from a database and make them into ListItems for a listbox?

    I'm trying to populate listbox1 with e-mails and then using a button to add a single value(at a time) to listbox2. In other words, listbox1 will have all the e-mails from the database and listbox2 will have only the e-mails that will get an e-mail. I can populate listbox1 with the database results, it just won't let me add any values to listbox2 from there. I'm thinking that it doesn't know the index value.

  2. #2
    Join Date
    Jul 2004
    Posts
    61

    Here's my code

    Dim conPubs As SqlConnection
    Dim cmdSelectAuthors As SqlCommand
    Dim dtrAuthors As SqlDataReader
    conPubs = New SqlConnection(ConfigurationSettings.appSettings("STDConnect"))
    conPubs.Open()
    cmdSelectAuthors = New SqlCommand("Select * from Email", conPubs)
    dtrAuthors = cmdSelectAuthors.ExecuteReader()
    While dtrAuthors.Read()
    Listbox1.Items.Add(dtrAuthors("email"))
    End While
    dtrAuthors.Close()
    conPubs.Close()

    Now, this works. It populates my listbox with the e-mails. The problem I'm having is not being able to add an e-mail from this listbox into listbox2 by highlighting and submitting a value. Any ideas?

  3. #3
    Join Date
    Jul 2004
    Posts
    1
    Here is how to add the selected item from ListBox1 to ListBox2:

    Code:
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
            ListBox2.Items.Add(ListBox1.SelectedItem)
    
        End Sub
    Hope that helps..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles