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

Async loading at the ItemsSource Level

3 Answers 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jitin Vishwakarma
Top achievements
Rank 1
Jitin Vishwakarma asked on 30 Mar 2010, 01:09 AM
Hi,

I am loading a huge amount of data in the GridView. The objects that I load to the Grid are dynamically generated using reflection.
Normally, I call ItemsSource when I am done creating all the objects (record items) from the data. This takes very long time as it has to wait till all the objects are created. What I would like to do is asynchronously add to the ItemsSource as the objects are created. How can I achieve this?

Code snippet:
      var listType = typeof(List<>).MakeGenericType(new[] { generetedType });
      var listOfCustom = Activator.CreateInstance(listType);

for()........
{
       object generetedObject = Activator.CreateInstance(generetedType);
        // Add Values to generetedType
        ........
     listType.GetMethod("Add").Invoke(listOfCustom, new[] { generetedObject });
}

myRadGrid.ItemsSource = listOfCustom as IEnumerable;   // About 1-2 minutes spent by now.

How can I update the ItemsSource within the loop?

Thanks,
Jitin




3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 30 Mar 2010, 07:10 AM
Hello Jitin,

You can use any INotifyCollectionChanged - the grid will react immediately change in such collection.

Sincerely yours,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jitin Vishwakarma
Top achievements
Rank 1
answered on 30 Mar 2010, 09:46 PM
Thanks Vlad,

When I try to create dynamic type that are derived from INotifyCollection - it turned out to be a costly affair. I takes lot more time to create objects and hence defeats the purpose. I am wondering if there is some other way to fire event to the grid to let it know that the collection changed instead of calling Rebind() ( because Rebind will refresh the whole grid - which we do not want)?

Thanks,
Jitin
0
Milan
Telerik team
answered on 31 Mar 2010, 07:13 AM
Hello Jitin Vishwakarma,

INotifyCollectionChanged is the standard way in WPF/Silverlight for notifying that collections have changed. Luckily this interface should be only implemented by the collection that is storing the data items. As far as I can see you are using a list to store your items:

1.var listType = typeof(List<>).MakeGenericType(new[] { generetedType });
2.var listOfCustom = Activator.CreateInstance(listType);

Since ObservableCollection implements INotifyCollectionChanged you only have to substitute the List<> with ObservableCollection<> to create a collection of objects that can notify the grid when its items have changed.

Now, whenever "  listType.GetMethod("Add").Invoke(listOfCustom, new[] { generetedObject });" is executed the grid will know that something has changed.


All the best,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Jitin Vishwakarma
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Jitin Vishwakarma
Top achievements
Rank 1
Milan
Telerik team
Share this question
or