Articles in this section
Category / Section

How to dynamically change the value of FreezeExpandColumn in the GridTreeControl?

2 mins read

In the WPF GridTreeControl, by default the first column is freezable. So when you change the width of the first column greater than the width of the Grid, then first column is freezed.  You cannot scroll and see the other columns as shown in the following screenshot.

The First column is freezed and the remaining columns are not seen in GridTreeControl

Figure 1: The First column is freezed and the remaining columns are not seen

You can overcome the above problem initially as well as dynamically.

Initial Loading:

On declaring the properties in XAML/code behind for the GridTreeControl, set the FreezeExpandColumn property to false in Grid to overcome the above problem. By default the FreezeExpandColumn property is true.

XAML

<syncfusion:GridTreeControl Name="treeGrid" 
                                        AllowDragColumns="True"
                                        AllowDrop="False"    
                                        ShowRowHeader="False"
                                        Background="Red"
                                        AllowSort="False"
                                        FreezeExpandColumn="False"
                                        ChildPropertyName="Children"
                                        EnableHotRowMarker="True"
                                        EnableNodeSelection="True"
                                        ExpandStateAtStartUp="AllNodesExpanded"
                                        ItemsSource="{Binding PersonDetails}"
                                        NotifyPropertyChanges="True"
                                        />

 

Run Time:

During runtime, you can set the FreezeExpandColumn property to false in the ScrollColumnsChanged and SizeChanged events of the ScrollViewer when resizing the columns or size of grid.

You can wire the ScrollColumnsChanged and SizeChanged events of the ScrollViewer inside the loaded event of the GridTreeControl as shown in the following code example,

C#

void InternalGrid_Loaded(object sender, RoutedEventArgs e)
  {
            //Wiring the ScrollColumns Changed event
            this.treeGrid.InternalGrid.ScrollColumns.Changed += ScrollColumns_Changed;
            //Wiring the ScrollOwner SizeChanged event
            this.treeGrid.InternalGrid.ScrollOwner.SizeChanged += ScrollOwner_SizeChanged;
   }

 

SizeChanged Event:

When the size of Grid is changed, SizeChanged event of the ScrollViewer gets triggered. In this case, you can get the index, based on the ScrollColumns count.  When the Treegrid width is lesser than the scrollcoumns width, change the FreezeExpandColumn property to false. Else you can set the FreezeExpandColumn property to true, when the Treegrid width is greater than the scrollcoumns width.

C#

void ScrollOwner_SizeChanged(object sender, SizeChangedEventArgs e)
  {
           treeGridSize = e.NewSize;
           // Calculating the index based on the ScrollColumns count
            int index = this.treeGrid.Model.TreeGrid.ScrollColumns.GetVisibleLines().Count == 1 ? 0 : 1;
            
            //Set the FreezeExpandColumn as false if the treegrid width less than the Scrollcolumns and FreezeExpandColumn as true
            if (this.treeGrid.FreezeExpandColumn && e.NewSize.Width < this.treeGrid.Model.TreeGrid.ScrollColumns.GetVisibleLines()[index].Size+SystemParameters.ScrollWidth)
                this.treeGrid.FreezeExpandColumn = false;
            //Set the FreezeExpandColumn as true if the treegrid width greater than the Scrollcol umns and FreezeExpandColumn as false
            else if (!this.treeGrid.FreezeExpandColumn && e.NewSize.Width > this.treeGrid.Model.TreeGrid.ScrollColumns.GetVisibleLines()[index].Size + SystemParameters.ScrollWidth)
                this.treeGrid.FreezeExpandColumn = true;
   } 

 

ScrollColumns Changed event:

On resizing the columns in the GridTreeControl, the ScrollColumnChanged event gets triggered. In this case, you can get the index based on the ScrollColumns count. Set the FreezeExpandColumn property to false when the Treegrid width is lesser than the scrollcoumns width.

 C#

void ScrollColumns_Changed(object sender, EventArgs e)
  {
            // Calculating the index based on the ScrollColumns count
            int index = this.treeGrid.InternalGrid.ScrollColumns.GetVisibleLines().Count == 1 ? 0 : 1;
            //Set the FreezeExpandColumn as false if the treegrid width less than the Scrollcolumns and FreezeExpandColumn as true
            if (this.treeGrid.FreezeExpandColumn && this.treeGrid.InternalGrid.ScrollColumns.GetVisibleLines()[index].Size + SystemParameters.ScrollWidth > treeGridSize.Width)
            {
                this.treeGrid.FreezeExpandColumn = false;
            }
  }

You can refer to the following sample link to change the FreezeExpandColumn property value in GridTreeControl,

Sample Link:  DynamicallyUnFreezeExpandColumn_WPF

 

Conclusion

I hope you enjoyed learning about how to dynamically change the value of  FreezeExpandColumn in the GridTreeControl.

 You can refer to our WPF GridTreeControl feature tour  page to know about its other groundbreaking feature representations. You can also explore  documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied