private void grdPlanning_RowLoaded(object sender, RowLoadedEventArgs e) { // set expandable property of the row to true if it has a child grid GridViewRow row = e.Row as GridViewRow; if (row != null) { // get the plan line and plan line view SCO_HierarchyPlanLine pl = row.DataContext as SCO_HierarchyPlanLine; SCO_HierarchyPlanViewLine pvl = pl.SCO_HierarchyPlanLineType.SCO_HierarchyPlanViewLine.FirstOrDefault(); //// set the Group Name and Order Num from the View Plan Line //pl.SCO_HierarchyPlanLineType.DefaultGroupName = pvl.GroupName; //pl.SCO_HierarchyPlanLineType.DefaultDisplayOrder = (short)pvl.DisplayOrderNum; if (pvl.SCO_HierarchyPlanViewLine2 != null) row.Visibility = System.Windows.Visibility.Collapsed; else row.Visibility = System.Windows.Visibility.Visible;5 Answers, 1 is accepted
In case you want to hide some rows from the grid, it is better to work directly with its Items and remove those you want to be hidden.
Maya
the Telerik team
I could use filtering if i could fire the filter routine after a property change on the filtered column in the below routine. Although if it has to go through all the items in the filtering process (not just the ones that changed) it will be too slow for this application.
private void grdPlanning_RowLoaded(object sender, RowLoadedEventArgs e) { // set expandable property of the row to true if it has a child grid // Setup indentation of main grid row GridViewRow row = e.Row as GridViewRow; if (row != null) { // get the plan line and plan line view SCO_HierarchyPlanLine pl = row.DataContext as SCO_HierarchyPlanLine; SCO_HierarchyPlanViewLine pvl = pl.SCO_HierarchyPlanLineType.SCO_HierarchyPlanViewLine.FirstOrDefault(); //row.IsExpandedChanged += new RoutedEventHandler(row_IsExpandedChanged); //// set the Group Name and Order Num from the View Plan Line //pl.SCO_HierarchyPlanLineType.DefaultGroupName = pvl.GroupName; //pl.SCO_HierarchyPlanLineType.DefaultDisplayOrder = (short)pvl.DisplayOrderNum; if (pvl.SCO_HierarchyPlanViewLine2 != null) { //row.Visibility = System.Windows.Visibility.Collapsed; grdPlanning.Items.Remove(pl); } else row.Visibility = System.Windows.Visibility.Visible;I would need a bit more information about the requirements you have and the scenario you want to achieve. When do you want to hide and show particular rows ? Why is it not appropriate for you to use the Filtering functionality of the grid ? Any relevant information about your purpose will be helpful.
Maya
the Telerik team
Hey Maya, thanks for your reply. The data bound in my grid comes from a flat data source (1 table). However it is financial data and some of the lines are better off viewed as sub-lines. For example, Forecast data could be a combination of Seasonal Forecast and Promotional Forecast and many others. I am using a custom Toggle column inherited from the Telerik Toggle column (I had to intercept the click event in order for it to fire when expected) and only showing this column as visible when I am on a line with sub-lines. When the user toggles this column, i would like to hide / show the sub-lines. Can you dynamically change the Row Style with some sort of selector based on a property change, or can you use a column filter that gets triggered when the column value changes ? I tried both of these and was able to get what i wanted on an initial load, but when i changed the field at runtime (when the user clicks the toggle) neither the row selector would update, nor the column filter. thx.
public class RowStyleSelector : StyleSelector { public override Style SelectStyle(object item, DependencyObject container) { if (item is SCO_HierarchyPlanLine) { SCO_HierarchyPlanLine pl = item as SCO_HierarchyPlanLine; if (pl.SCO_HierarchyPlanLineType.CellDisplayType == "Hidden") { return EmptyRowStyle; } else { return NormalRowStyle; } } return null; } public Style NormalRowStyle { get; set; } public Style EmptyRowStyle { get; set; } }ColumnFilterDescriptor filter = new ColumnFilterDescriptor((IDataFieldDescriptor)this.grdPlanning.Columns[6]); filter.FieldFilter.Filter1.Operator = Telerik.Windows.Data.FilterOperator.IsEqualTo; filter.FieldFilter.Filter1.Value = "Visible"; this.grdPlanning.FilterDescriptors.Add(filter);
private void CustomToggleButton_ClickEvent(object Sender, RoutedEventArgs e) { GridViewToggleButton gvtb = (GridViewToggleButton)Sender; SCO_HierarchyPlanLine pl = gvtb.DataContext as SCO_HierarchyPlanLine; SCO_HierarchyPlanViewLine pvl = pl.SCO_HierarchyPlanLineType.SCO_HierarchyPlanViewLine.FirstOrDefault(); foreach (SCO_HierarchyPlanViewLine pvlChild in pvl.SCO_HierarchyPlanViewLine1) { SCO_HierarchyPlanLine pl2 = pvlChild.SCO_HierarchyPlanLineType.SCO_HierarchyPlanLine.FirstOrDefault(); foreach (GridViewRow row in grdPlanning.ChildrenOfType<GridViewRow>()) { if (row.DataContext != null && row.DataContext.GetType() == typeof(SCO_HierarchyPlanLine)) { SCO_HierarchyPlanLine pl3 = row.DataContext as SCO_HierarchyPlanLine; if (pl2.PlanLineType == pl3.PlanLineType) { if (gvtb.IsChecked == true) { // bound column pl3.SCO_HierarchyPlanLineType.CellDisplayType = "Visible"; } else { // bound column pl3.SCO_HierarchyPlanLineType.CellDisplayType = "Hidden"; } } } } } // should fire PropertyChanged event and trigger filter? _ctx.SubmitChanges(); }Following up your scenario, I may suggest you to take a look at the RadTreeListView control. It may be a more appropriate choice for your requirements.
However, considering the RadGridView, you may take a look at our demo for CustomHierachy. It shows how to work with the IsExpandable property of the GridViewRow and provide a toggle button only for those items that have children. Furthemore, if you want to proceed with some kind of StyleSelectros, you may again look at our demos for RowStyleSelector.
Let me know which is the most appropriate solution for your scenario and whether you need any further assistance.
Maya
the Telerik team