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

RowIndicator invisible with backgroundworker in MVVM

5 Answers 55 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Prashant
Top achievements
Rank 1
Prashant asked on 28 Oct 2019, 01:28 AM

Hi All,

I am using RadGridView with MVVM binding. I am pulling large amount of data i.e.5000 records from database so used BackgroundWorker for data processing.

In RunWorkerCompleted event  i am assigning data to ObservableCollection which is my grid's ItemsSource.

Everything works well except rowindicator, it's not visible if i bind data in worker completed event.

If i remove background worker and execute process on main thread then rowindicator displayed on grid.

 

Here is my sample code;

  public ObservableCollection<Assets> AssetDs { get; set; } = new ObservableCollection<Assets>();

   private voids search()
        {

          BackgroundWorker bw = new BackgroundWorker();

           bw.DoWork += (sender, e) =>
                {
                   e.Result = //DB call to fetch records 
                };

            bw.RunWorkerCompleted += (sender, e) =>
                {

                     List<Asset> result = (List<Asset>)e.Result;

                     result.ForEach(a => AssetDs.Add(a));

                 }

               bw.RunWorkerAsync();

          }

Any help would be appreciated,

Prashant

 

 

 

 

5 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 30 Oct 2019, 01:18 PM

Hello Prashant,

Thank you for the provided code snippet.

Will you find it possible to use QueryableCollectionView as the type of your AssetDs collection? When such type of ItemsSource is passed to the control, there is no need for synchronization between the control's Items collection and this source and the current item should be updated as expected.

I've prepared a small sample project to demonstrate such an approach. Please have a look and let me know if a similar setup would be possible in your application.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Prashant
Top achievements
Rank 1
answered on 30 Oct 2019, 11:57 PM

Hi Dilyan,

Really appreciate your help, indicator issue has been resolved.

One more question, my grid is updating dynamically based on search criteria. I need to remove old values and bind new data based on query result.

Is there any way to clear all items from QueryableCollectionView?

Regards,

Prashant

 

 

0
Accepted
Dilyan Traykov
Telerik team
answered on 31 Oct 2019, 01:37 PM

Hi Prashant,

Even though the QueryableCollectionView does not expose a Clear method itself, you can invoke this method on the SourceCollection. You will, however, also need to call the Refresh method afterward.

            (AssetDs.SourceCollection as IList).Clear();
            AssetDs.Refresh();
Please let me know whether this works for you.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Prashant
Top achievements
Rank 1
answered on 01 Nov 2019, 04:23 AM

It works..Thank you Dilyan for help.

Regards,

Prashant 

 

0
Dilyan Traykov
Telerik team
answered on 01 Nov 2019, 03:05 PM

Hi Prashant,

I'm happy to hear that the proposed solution worked for you. Do let me know if I can further assist you with anything else.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Prashant
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Prashant
Top achievements
Rank 1
Share this question
or