two-column display member for data-bound combo box

Posted on 2007-08-02
Last Modified: 2013-11-26
In VB.NET 2005, I have a data-bound combo box.  I've clicked the smart tag on it, selected a Data Source, Display Member, and Value Member.  My question is:  Can I select TWO columns to display as the Display Member?  For example:  The value member is an employee ID.  But I'd like the display member to be from two columns, employee first name and employee last name with a space in between.  Thanks!
Question by:redmission
    LVL 46

    Accepted Solution

    Hi redmission,

    If you use a DataAdapter to fill a dataset, you can modify the SELECT statement to concatenate 2 fields....

        SELECT *,  ([FirstName] & " " & [LastName]) AS FullName FROM YourTable

    ...then set the display member to [FullName].



    Author Comment

    Thanks webtubbs...that did it!  Here is my SQL Query on that I entered on the TableAdapter in Design View for the Fill method:  

    SELECT     *, OFFER1 + N' / ' + OFFER2 AS Expr1
    FROM         OLP_OFFERS

    This allowed me to select the OfferBindingSource as the DataSource of the combo box, with a Display Member of Expr1.  The only problem was that if one of the offers was wouldn't display the Expr1 for that record at all.  I just set all the nulls in the DB to be blanks...but still.  Other than that, It works great!  You saved the day!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now