faroke moahmed
faroke moahmed

Reputation: 313

loading multiple contents from an ARRAY[] in to listbox in wp8

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..

Upvotes: 1

Views: 298

Answers (2)

har07
har07

Reputation: 89325

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>

Upvotes: 1

Hitesh
Hitesh

Reputation: 3498

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;

Upvotes: 0

Related Questions