We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WPF |
Control: GridTreeControl |
.NET Framework: 4.5 |
Product Version: 12.4.0.24
Tags: columns

In the 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

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile