This is a migrated thread and some comments may be shown as answers.

Item does not automatic add to list

3 Answers 40 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Joshua
Top achievements
Rank 1
Joshua asked on 30 May 2014, 08:02 AM
Hi,
I'm trying to add new item to DataBoundListBox but it's just showing "Loading" :
This is my code :

 public partial class Page1 : PhoneApplicationPage
{
    // Constructor

    List<Employee> listEmployee = new List<Employee>()
    {
         new Employee(){Name = "John",Age = 24, ImgUrl = "1.jpg",Company = "MICROSOFT"},
         new Employee(){Name = "Smith",Age = 30, ImgUrl = "2.jpg",Company = "MICROSOFT"},
         new Employee(){Name = "Brown",Age = 35, ImgUrl = "3.jpg",Company = "MICROSOFT"},
         new Employee(){Name = "Taylor",Age = 33, ImgUrl = "4.jpg", Company = "MICROSOFT"},
    };

    public Page1()
    {
        InitializeComponent();
        lstEmployee.ItemsSource = listEmployee;
        lstEmployee.DataVirtualizationMode = Telerik.Windows.Controls.DataVirtualizationMode.OnDemandAutomatic;
        lstEmployee.DataRequested += this.OnDataRequested;
    }

    private void OnDataRequested(object sender, EventArgs args)
    {
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });
        listEmployee.Add(new Employee() { Name = "aaaa", Age = 24, ImgUrl = "1.jpg", Company = "MICROSOFT" });

    }
}

3 Answers, 1 is accepted

Sort by
0
Joshua
Top achievements
Rank 1
answered on 30 May 2014, 08:19 AM
This is my XAML :
<telerikPrimitives:RadDataBoundListBox Name="lstEmployee">
                <telerikPrimitives:RadDataBoundListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"  />
                                <ColumnDefinition Width="*"  />
                            </Grid.ColumnDefinitions>
                            <TextBlock Margin="10" VerticalAlignment="Center" Text="{Binding Name}" FontSize="30" Grid.Column="1"></TextBlock>
                        </Grid>
                    </DataTemplate>
                </telerikPrimitives:RadDataBoundListBox.ItemTemplate>
            </telerikPrimitives:RadDataBoundListBox>
0
Accepted
Ivaylo Gergov
Telerik team
answered on 30 May 2014, 08:32 AM
Hi Joshua,

In this case the problem is that the RadDataBoundListbox.ItemsSource is of type List<T> which does not implement the INotifyCollectionChanged interface and the RadDataBoundListBox is not notified about the new items that have been added. If you use ObservableCollection<T> instead, everything should work as expected.

Let me know how it goes.


Regards,
Ivaylo Gergov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Joshua
Top achievements
Rank 1
answered on 30 May 2014, 08:40 AM
Hi,
It works now.
Tags
DataBoundListBox
Asked by
Joshua
Top achievements
Rank 1
Answers by
Joshua
Top achievements
Rank 1
Ivaylo Gergov
Telerik team
Share this question
or