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); } }
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; } }