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

[Solved] Collapsed rows show blank visual space

5 Answers 290 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
David
Top achievements
Rank 1
David asked on 30 Nov 2010, 11:39 PM
I have been trying to hide and show rows based on the Visibililty property of the GridViewRow.  When I set this property to Collapsed in the Row_Loaded event I get blank lines in the grid.  I expected these rows not to take up any of the visual space.  Any recommendations, thx.

 

 

 

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

Sort by
0
Maya
Telerik team
answered on 01 Dec 2010, 07:58 AM
Hi David,

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.
 

Kind regards,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
David
Top achievements
Rank 1
answered on 01 Dec 2010, 06:23 PM
Thanks for your reply.  I tried removing the item in this same routine (Row_Loaded), and it was still rendered.  Anything else you can think of?  Is there anyway to force the height of a row to 0?
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;
0
Maya
Telerik team
answered on 02 Dec 2010, 12:24 PM
Hello David,

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.
  

All the best,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
David
Top achievements
Rank 1
answered on 02 Dec 2010, 06:28 PM

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();      
              
        }
0
Maya
Telerik team
answered on 03 Dec 2010, 11:02 AM
Hi David,

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.

All the best,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Maya
Telerik team
David
Top achievements
Rank 1
Share this question
or