Group items counter displayed in group item

3 posts, 1 answers
  1. Artem
    Artem avatar
    16 posts
    Member since:
    May 2013

    Posted 12 Dec 2012 Link to this post

    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. Answer
    Ivan Todorov
    Ivan Todorov avatar
    688 posts

    Posted 15 Dec 2012 Link to this post

    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.

    Ivan Todorov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. Artem
    Artem avatar
    16 posts
    Member since:
    May 2013

    Posted 16 Dec 2012 Link to this post

    Thank you very much for the working solution :)
Back to Top