Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
590
XamWebGrid Expand All/Collapse All rows
posted

I am using XamWebGrid 10.1 with ColumnLayout to show Parent/Details, and using the ContextMenu from the Siliverlight Control toolkit.  It never expands any of the rows. 

        private void dg_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
        }

        private void dg_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            cMenu = new ContextMenu();
            menuItem = new MenuItem();
            menuItem.Header = "Expand All";
            cMenu.Items.Add(menuItem);
            menuItem.Click += new RoutedEventHandler(menuItem_Click);

            menuItem = new MenuItem();
            menuItem = new MenuItem();
            menuItem.Header = "Collapse All";
            cMenu.Items.Add(menuItem);
            menuItem.Click += new RoutedEventHandler(menuItem_Click);

            cMenu.IsOpen = true;
            cMenu.HorizontalOffset = e.GetPosition(LayoutRoot).X;
            cMenu.VerticalOffset = e.GetPosition(LayoutRoot).Y;
        }

        void menuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mnu = sender as MenuItem;

            switch (mnu.Header.ToString())
            {
                case "Expand All":
                    foreach (Row r in dg.Rows)
                    {
                        if (r.RowType == RowType.DataRow)
                            ExpandAllChildRows(r);
                    }
                    break;
                case "Collapse All":
                    foreach (Row r in dg.Rows)
                    {
                        if (r.RowType == RowType.DataRow)
                            CollapseAllChildRows(r);
                    }
                    break;
                default:
                    break;
            }
        }
        private void ExpandAllChildBands(ChildBand parentBand)
        {
            foreach (Row r in parentBand.Rows)
            {
                r.IsExpanded = true;
                if (r.HasChildren)
                    ExpandAllChildRows(r);
            }
        }

        private void ExpandAllChildRows(Row parentRow)
        {
            foreach (ChildBand cb in parentRow.ChildBands)
            {
                cb.IsExpanded = true;
                if (cb.HasChildren)
                    ExpandAllChildBands(cb);
            }
        }

        private void CollapseAllChildBands(ChildBand parentBand)
        {
            foreach (Row r in parentBand.Rows)
            {
                r.IsExpanded = false;
                if (r.HasChildren)
                    CollapseAllChildRows(r);
            }
        }

        private void CollapseAllChildRows(Row parentRow)
        {
            foreach (ChildBand cb in parentRow.ChildBands)
            {
                cb.IsExpanded = false;
                if (cb.HasChildren)
                    CollapseAllChildBands(cb);
            }
        }
Parents
No Data
Reply
  • 590
    Verified Answer
    posted

    I solved my own problem.  I never added r.IsExpanded = true before calling ExpandAllRows, and also didn't add r.IsExpanded = false before calling CollapseAllRows.  I only have 1 level of details.  It's monday.

            void menuItem_Click(object sender, RoutedEventArgs e)
            {
                MenuItem mnu = sender as MenuItem;

                switch (mnu.Header.ToString())
                {
                    case "Expand All":
                        foreach (Row r in dg.Rows)
                        {
                            if (r.RowType == RowType.DataRow)
                                ExpandAllChildRows(r);
                        }
                        break;
                    case "Collapse All":
                        foreach (Row r in dg.Rows)
                        {
                            if (r.RowType == RowType.DataRow)
                                CollapseAllChildRows(r);
                        }
                        break;
                    default:
                        break;
                }
            }

Children
No Data