collapse/expand on mouseclick

2 posts, 1 answers
  1. Andre
    Andre avatar
    41 posts
    Member since:
    Feb 2018

    Posted 24 Jan 2019 Link to this post

    i would like to expand or collapse the group by clicking on the group name.
    my code crashes at e.Item.Group because Group is null.
    why is group null when i click on the group name?

            private void Operation_lv_ItemMouseClick(object sender, ListViewItemEventArgs e) {
                if (e.Item.Group != null) {
                    e.Item.Group.Expanded = !e.Item.Group.Expanded;
                }
            }

    many thanks

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2938 posts

    Posted 24 Jan 2019 Link to this post

    Hi Andre,

    The item is the group in this case and it does belong to a group. Here is how you can achieve this:
    private void RadListView1_ItemMouseClick(object sender, Telerik.WinControls.UI.ListViewItemEventArgs e)
    {
        var item = e.Item as ListViewDataItemGroup;
        if (item != null && !item.Expanded)
        {
            item.Expanded = true;
        }
    }

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    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.
Back to Top