Collapse ListView Groups by default

7 posts, 0 answers
  1. Mano Sadeh
    Mano Sadeh avatar
    12 posts
    Member since:
    May 2010

    Posted 01 Oct 2018 Link to this post

    Hey

    Can we initialize RadListView control with Grouping that all groups are collapsed by default?

    Thanks,

    Mano

  2. Lance | Manager Technical Support
    Admin
    Lance | Manager Technical Support avatar
    1168 posts

    Posted 01 Oct 2018 Link to this post

    Hello Mano,

    There's no initialization property that does this, however you can achieve the same effect by programmatically collapsing the groups. See here for more information: Expand and Collapse Groups.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Иван
    Иван avatar
    2 posts
    Member since:
    Aug 2012

    Posted 02 Oct 2018 in reply to Lance | Manager Technical Support Link to this post

    I added next code:

    lvWorkTasks.PropertyChanged += LvWorkTasks_PropertyChanged;

            private void LvWorkTasks_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                if (e.PropertyName.Equals("ItemsSource"))
                {
                    lvWorkTasks.GetDataView().CollapseAll();
                }
            }

    But when CollapseAll method is called then null reference exception appears for Items property.
  4. Lance | Manager Technical Support
    Admin
    Lance | Manager Technical Support avatar
    1168 posts

    Posted 02 Oct 2018 Link to this post

    Hi Ivan,

    I see that you opened a support ticket for the same question and my colleague has replied. I will share the reason you're having that problem, along with the solution, here with the community as well.

    Problem:
    Using the Xamarin.Forms PropertyChanged event handler, to check when ItemsSource has changed, is too soon in the lifecycle because the native control's items haven't had a chance to be populated yet.

    Solution:
    You can instead use the NativeControlLoaded event, which will fire when the native TKExtendedListView control is ready.

    // event subscription (can also be done in XAML)
    listView.NativeControlLoaded += listView_NativeControlLoaded;
     
    // event handler
    private void listView_NativeControlLoaded(object sender, EventArgs e)
    {
        var dataView = this.listView.GetDataView();
     
        dataView.CollapseAll();
    }


    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Иван
    Иван avatar
    2 posts
    Member since:
    Aug 2012

    Posted 02 Oct 2018 in reply to Lance | Manager Technical Support Link to this post

    The same exception in that case
    System.NullReferenceException: 'Object reference not set to an instance of an object.' 
  6. Lance | Manager Technical Support
    Admin
    Lance | Manager Technical Support avatar
    1168 posts

    Posted 02 Oct 2018 Link to this post

    Hi Ivan,

    If you're continuing to see that behavior, there is likely another factor specific to how your application loads data.

    Run the demo we sent you in the ticket to see that it works as expected using the recommendation. Then, update the demo so that it replicates the exception and send it back to Didi in that ticket thread for further investigation. She will be able to investigate directly and provide a more appropriate solution for that scenario.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Parvez
    Parvez avatar
    1 posts
    Member since:
    Jan 2019

    Posted 14 Nov 2019 in reply to Lance | Manager Technical Support Link to this post

    what work around i did.. because its giving me the count zero , so again i am checking it after full list get loaded. May be this will help you.

    public SubSectionEquipmentPage()
            {
                InitializeComponent();
                MyListView.NativeControlLoaded += MyLisView_NativeControlLoaded;
            }

            private void MyLisView_NativeControlLoaded(object sender, System.EventArgs e)
            {
                CollapseList();
            }

            public async void CollapseList()
            {
                var dataView = this.MyListView.GetDataView();
                if (dataView != null && dataView.Items.Count>0)
                {
                    dataView.CollapseAll();
                }
                else
                {
                    await Task.Delay(2000);
                    CollapseList();
                }
            }

Back to Top