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

collapse/expand on mouseclick

1 Answer 20 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Andre
Top achievements
Rank 1
Andre asked on 24 Jan 2019, 10:34 AM

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

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 24 Jan 2019, 01:39 PM
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.
Tags
ListView
Asked by
Andre
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or