Results 1 to 4 of 4

Thread: Database one column to ListBox?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2015
    Posts
    80

    Database one column to ListBox?

    Hi,

    From my database I have managed to fire a query so select just one column of the name of the details I want.
    It shows up fine in the data grid but I want to use ListBox instead of DataGrid.

    How can I achieve this?


    Here is my code:



    This is the result:




    Please let me know what I can do.

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Database one column to ListBox?

    Start by posting code as text wrapped in code tags...

    You need to set the DisplayMember of the list box to the data table column name.

    Code:
    ListBox1.DisplayMember="CName"
    I can't remember whether the DisplayMember should be set before or after the data source is set, but I do believe it matters.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Database one column to ListBox?

    DisplayMember and ValueMember both need to be set BEFORE the DataSource ... Doesn't matter which order Display/Value member gets set, they just need to be set before the datasource.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2015
    Posts
    80

    Re: Database one column to ListBox?

    Quote Originally Posted by kebo View Post
    Start by posting code as text wrapped in code tags...

    You need to set the DisplayMember of the list box to the data table column name.

    Code:
    ListBox1.DisplayMember="CName"
    I can't remember whether the DisplayMember should be set before or after the data source is set, but I do believe it matters.
    Quote Originally Posted by techgnome View Post
    DisplayMember and ValueMember both need to be set BEFORE the DataSource ... Doesn't matter which order Display/Value member gets set, they just need to be set before the datasource.

    -tg

    Thanks guys, that worked! Thank you so much! +rep.

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