Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7048181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:51:39+00:00 2026-05-28T02:51:39+00:00

I am trying to get a ListBox to display a concatenation of multiple rows

  • 0

I am trying to get a ListBox to display a concatenation of multiple rows of table Accommodation.

Because I can’t edit the datasource, I prepared a class, AccommodationEntity, which contains both the original Accommodation object and the string I want the ListBox to display.

However, for some reason, I fail to set the DisplayMember property of the ListBox, which thus displays the default jibber-jabber.

I set up the listbox as follows:

accommodationList.DisplayMember = "textToShow";
// load and set up accommodation
List<AccommodationEntity> relatedAccommodations = 
    dt.listHolidayAccommodation(relatedHoliday);
accommodationList.DataSource = relatedAccommodations;
accommodationList.Refresh();

The class for the objects stored in the datasource looks like this:

class AccommodationEntity
{
    public accommodation classicAccommodation;
    public string textToShow;

    public AccommodationEntity(stay relatedStay)
    {
        this.classicAccommodation = relatedStay.accommodation;

        string from = relatedStay.dateFrom.ToString();
        string to = relatedStay.dateTo.ToString();
        string city = relatedStay.accommodation.location.ToString();
        string hotelName = relatedStay.accommodation.name.ToString();

        this.textToShow = hotelName + ", " + city + " (" + from + " - " + to + ")";
    }
}

}
`

And finally, there is a method which does some searching (returning correct objects):

public List<AccommodationEntity> listHolidayAccommodation(holiday selectedHoliday)
{
    List<AccommodationEntity> ubytovani = new List<AccommodationEntity>();

    var stays = from singleStay in selectedHoliday.stays
                select singleStay;

    foreach (stay singleStay in stays)
    {
        AccommodationEntity newStay = new AccommodationEntity(singleStay);
        ubytovani.Add(newStay);
    }

    return ubytovani;
}

I know the dataSource contains the right data, but for some reason, it seems the DisplayMember property remains set to "".

Any help would be appreciated.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:51:39+00:00Added an answer on May 28, 2026 at 2:51 am

    Did you try to set the DisplayMember and DisplayValue like this. Where “Name”/”Value” is the name of the property in the Accomodation class.

    List<AccommodationEntity> relatedAccommodations = dt.listHolidayAccommodation(relatedHoliday);
    accommodationList.DataSource = relatedAccommodations;
    accommodationList.DisplayMember = "Name";
    accommodationList.ValueMember = "Value";
    

    UPDATE:

    Make sure textToShow is actually a Property, not just a public field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get index of each items in a listbox Here is
Trying to get this expression to work, can someone look at it and tell
I am trying to display filenames in a listbox, retrieved from a particular directory.
i'm currently developing an application to windows phone 7 i'm trying to get multiple
Using XAML, I am trying to get a list box to display the list
I am trying to get the text of the selected item of a listbox.
I am trying to get a list of all elements from ListBox if no
I am trying to get the selected items of an asp:ListBox control and put
I am trying to parse this xml and can successfully get the name and
I am trying to get text from an entry in my winForms ListBox by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.