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

Group items counter displayed in group item

2 Answers 240 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Artem
Top achievements
Rank 1
Artem asked on 12 Dec 2012, 01:09 PM
Hi, guys.
I am really sorry if I am asking something that is already is answered. But I swear I tried to search for it using Google and internal forum search.

Ok, I am using RadListView control in  ListViewType.IconsView view. And I am placing my items into groups and I do show groups.

It all started when I placed many items to the list. I immediately saw that the list is displayed with vast scroll and user see only the top of the list and only the first group. So I decided to collapse all groups when I load my items into list.
/// <summary>
/// Collapses all groups in channel pair list
/// </summary>
private void CollapseAllListGroups()
{
    foreach (var group in PairControlList.Groups)
        group.Expanded = false;
}

By the way, if it is not the best way to do so - you can tell me, because I was looking for some function like "Collapse all groups" and didn't find it. If I missed it - tell me, if not - it would be good to have one already implemented for RadListView control.

Oh.. back to things. My groups all appeared collapsed, and then I saw that it is hard for user to decide where to go, since some groups might be empty and some may have hundreds of items. So, what I want to do is to display the count of items in each group on the group item. (See attached picture)
I didn't found how to do such a thing. I believe that it has to be built in functionality of  group item in RadListView. Again, if I've missed it - just tell me.
And I tried to implement it, but no success...  was thinking about changing group item text on VisualItemCreating event, but at the same time I may not know the number of items that will be placed to each group... and items will be removed/added to the groups later.

Best regards

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 15 Dec 2012, 01:58 PM
Hi Artem,

Thank you for contacting us.

The proper way to achieve this functionality is to handle the VisualItemFormatting event:
void radListView1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
{
    BaseListViewGroupVisualItem groupItem = e.VisualItem as BaseListViewGroupVisualItem;
    if (groupItem != null)
    {
        groupItem.Text = groupItem.Data.Text + " (" + ((ListViewDataItemGroup)groupItem.Data).Items.Count + ")";
    }
}

As to collapsing all groups, you are using the correct approach. We will consider exposing CollapseAll/ExpandAll methods if more people request such.

If you have any further questions, do not hesitate to ask.

Regards,
Ivan Todorov
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Artem
Top achievements
Rank 1
answered on 16 Dec 2012, 06:40 AM
Thank you very much for the working solution :)
Tags
ListView
Asked by
Artem
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Artem
Top achievements
Rank 1
Share this question
or