Results 1 to 3 of 3

Thread: [2003] ListBox DataSource problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    2

    [2003] ListBox DataSource problem

    Hi folks,

    I'm a newbie having problems with binding tabledata to a ListBox.
    Already searched the forum but didn't find a suitable solution.

    This ist what I wanna have:
    A ListBox filled with the "names"-column of my usertable. But if clicked on the name the corrosponding id should be returned. This is what my code looks like:

    Code:
    Private Sub load_users()
            Dim ds As New DataSet()
            ds.Tables.Add(New DataTable("Users"))
            Dim da As SqlDataAdapter
    
            conn = New SqlConnection(myConnectString)
            conn.Open()
            da = New SqlDataAdapter("SELECT * FROM rmp_users ORDER BY LastName ASC", conn)
            da.Fill(ds, "Users")
            ListBox1.ValueMember = "id"
            ListBox1.DisplayMember = "LastName"
            ListBox1.DataSource = ds.Tables("Users")
            conn.Close()
        End Sub
    But in the ListBox it only shows entries displaying "System.Data.DataRowView".

    Can anyone help me out with that? I have no clue.

    Another question:
    Can I put two columns into the ListBox1.DisplayMember (like "FirstName" + "LastName")?

    Thanx for your help!

    Tim

  2. #2
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2003] ListBox DataSource problem

    A listview might be more of your thing, it can display nice columns like in windows task manage.
    If this post helped you, please click the rate button to say thank you! Remember to mark the thread as resolved too.
    Autoclicker, Hide Taskbar, Sounds on internal speaker, Changing Start Button Text (with code)

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    2

    Re: [2003] ListBox DataSource problem

    The column-thing is not that important. I need a method to get returned a userid after selecting a username. If that is possible with a listview - even better.

    Tim

Posting Permissions

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



Click Here to Expand Forum to Full Width