using 2 fields as a listbox display member

Posted on 2011-05-12
Last Modified: 2012-05-11
I have:
lstDept.DataSource = ReportHelper.GetDepartments
        lstDept.DisplayMember = "DepartmentID"
        lstDept.ValueMember = "DepartmentID"

Thsi works fine.

Is there a way of using the two fields as the display though so say:
lstDept.DisplayMember = "DepartmentID" & " - " & "Department"
Question by:scm0sml
    LVL 69

    Expert Comment

    by:Éric Moreau
    you have to do it in your SQL query

    Author Comment

    Its not really an option for me so does that mean the answer is no this can't be done?
    LVL 69

    Accepted Solution

    no from the DisplayMember itself.

    can you add a computedColumn to your dataTable?
    LVL 83

    Assisted Solution

    What is .GetDepartments returning? If its a datatable then change your code to this

    Dim dTable As DataTable = ReportHelper.GetDepartments
    dTable.Columns.Add("Display", GetType(String), "DepartmentID + ' - ' + Department")
    lstDept.DataSource = dTable
    IstDept.DisplayMember = "Display"
    lstDept.ValueMember = "DepartmentID"

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 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

    18 Experts available now in Live!

    Get 1:1 Help Now