1

I would like to know how to load multiple data from url and display in the listbox..

My Class Organization..

public class Organization : BaseModel
    {

        public int id {get;set;}
        public string address {get;set;}
        public string city { get; set; }
        public string contact1 {get; set;}
        public string contact2 {get; set;}
        public string country {get; set;}
        public string description {get; set;}
        public Event[] events {get; set;}//Need to load the Event data in listbox
}

My Event[] class..

public class Events: BaseModel
{
        public int id { get; set; }
        public DateTime event_date { get; set; }
        public string event_day { get; set; }
        public string event_location { get; set; }
        public DateTime event_time { get; set; }
}

I need to load the Event[] data into list box can any one help me to solve this problem..

Thanks in advance..

1
  • 1
    why dont you use a list or collection in plasce of array ? Commented Dec 11, 2013 at 6:20

2 Answers 2

1

If you didnt use data binding and simply want to display your Events property in listbox then it will be:

foreach (var Event in Events)
{
    listBox1.Items.Add(Event);
}

//and in the ListBox, specify which property of Event to be displayed
<ListBox x:Name="listBox1" DisplayMemberPath="Name"/>

Or i may be missing something in the question, since it seems to be too straight forward..

UPDATE : To display more than one property value in each listbox item you need to specify ItemTemplate instead of simply setting DisplayMemberPath. For example:

<ListBox x:Name="listBox1">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" >
                <TextBlock Text="{Binding name}" Margin="0,0,10,0"/>
                <TextBlock Text="{Binding address}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Sign up to request clarification or add additional context in comments.

4 Comments

thank-you.. it works good.. my single value has nearly 7 data.. so i can successfully get the single array[] value..but i need to extract all the value of array..eg:Array[0]={"name","id","address",..},array[1]={"name","id","address",..},array[2]={"name","id","address",..},..
i dont get what you mean, so you have two dimensional array? That means different problem then the one you stated in question. Or you just want to display all properties of Event in the ListBox instead of only one?
i need to display all the properties of Event[]
if that is the case, see update section of my answer. You can add more TextBlock to display more property, or create your own template if you want
0

Instead of using

public Event[] Events {get; set;}

use

public List<Event> Events {get; set;}

add items into your list with

Events.Add(new Events
{
  id = 1,
  event_day = today
});

and bind it to listbox with

listbox.itemsource = Events;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.