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

Showing Number of Items

2 Answers 350 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rayne
Top achievements
Rank 1
Rayne asked on 26 Sep 2011, 01:55 PM
I'm having trouble showing the actual number of items in my grid. When the application loads there are no items. The grid is bound to an ObservableCollection. When the user selects a query option from a list, the ViewModel clears the OC and adds the result items from the chosen query. This is done via background worker, then the results are cast to an IList and added to the collection via the OC.Add method.

What I want to do is show the user how many items are in the grid at any given time. It's working to some extent. As long as I don't change the initial query, it works. I have a textblock binding to the GridView's Items.ItemCount property.

The problem comes when I filter the results, then try to do a different query. The GridView's ItemCount isn't updating appropriately. Sometimes it shows 0 when there are clearly 3 items in the grid. If I clear the filters or change the filters for that query, the number gets reset and from them on it works properly, until I change the query.

For example, one query returns all records. There are 73. If I filter the grid on a status column to show all closed, it tells me there are 19. If I then try to run a different query, this one shows 3 items in the grid (because there are 3 items with closed status). The grid keeps the filtering and applies it to the new results. But the count shows 0. If I then change back to the original all records query, the count shows 1 even though the original 19 filtered records are once again shown in the grid.

So how do I get the correct count no matter how the grid is populated or filtered? I can't bind to the count of the bound collection, because if the user filters the grid, I want to show the filtered total. Basically (the total items that are displayed or visible).

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 28 Sep 2011, 01:10 PM
Hi Rayne,

 I have created a test application following your instructions.

If I bind the TextBlock to the ItemCount property of the RadGridView.Items, then the correct item count is displayed.

<TextBlock Text="{Binding ElementName=clubsGrid, Path=Items.ItemCount}"/>

 Still if I bind to the RadGridView.Items.Count, then indeed the '0' value is shown initially. In your description you told that you are binding to ItemCount. Is that correct?

Please check the sample and let me know how it differentiates from your project.

Best wishes,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Rayne
Top achievements
Rank 1
answered on 28 Sep 2011, 05:52 PM
Ok I figured out what's going on. If I create a new observableCollection, fill it and assign it to the viewmodel property as you did, It accurately displays the count. But if I just clear the collection (on the viewmodel) and refill it, it doesn't show the right count.
This can be easily reproduced in the sample you provided.

I figured I could clear the collection then add new items to it and the count would work. But it doesn't.
Tags
GridView
Asked by
Rayne
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Rayne
Top achievements
Rank 1
Share this question
or