GridTreeControl questions

How do I hide the expand-collapse button ?

I have a TreeGridCheckBoxColumn and for some rows I want to hide the checkbox, how to do that ?

How to add spacing between Top most level rows only ? Children rows shouldn't have any spacing

How to scroll to a specific source object ?

How to style a columns' top level cells ?



5 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team January 17, 2022 02:33 PM UTC

Hi John, 

From the mentioned details it seems you are using SfTreeGrid. Please refer the below given details.  

How do I hide the expand-collapse button ? 
You can hide the expand/collapse button by including custom template for TreeGridExpander as shown below.  

Code example :  

<Window.Resources> 
    <Style TargetType="syncfusion:TreeGridExpander" > 
        <Setter Property="Template"> 
            <Setter.Value> 
                <ControlTemplate TargetType="syncfusion:TreeGridExpander"> 
                    <Grid Background="{TemplateBinding Background}" 
                    SnapsToDevicePixels="True"> 
                    </Grid> 
                </ControlTemplate> 
            </Setter.Value> 
        </Setter> 
    </Style> 
</Window.Resources> 

Please refer the sample from the provided link. 


I have a TreeGridCheckBoxColumn and for some rows I want to hide the checkbox, how to do that ? 
You can achieve this by creating TreeGridTemplateColumn with CellTemplateSelector instead of using TreeGridCheckBoxColumn.  
Xaml :  
<Window.Resources> 
    <DataTemplate x:Key="CheckBoxTemplate"> 
        <CheckBox IsChecked="{Binding IsChecked}" VerticalAlignment="Center" HorizontalAlignment="Center" syncfusion:FocusManagerHelper.FocusedElement="True"/> 
    </DataTemplate> 
    <DataTemplate x:Key="EmptyTemplate"> 
        <Grid/> 
    </DataTemplate> 
    <local:CustomCellTemplateSelector x:Key="selector"/> 
</Window.Resources> 
 
<syncfusion:SfTreeGrid.Columns> 
    <syncfusion:TreeGridTemplateColumn MappingName="IsChecked" CellTemplateSelector="{StaticResource selector}"/> 
</syncfusion:SfTreeGrid.Columns> 

CS

public class CustomCellTemplateSelector : DataTemplateSelector 
{ 
 
    public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container) 
    { 
 
        if (item == null) 
            return null; 
        var data = item as EmployeeInfo; 
 
        if (data.ID % 2 == 0) 
            return Application.Current.MainWindow.FindResource("CheckBoxTemplate") as DataTemplate; 
 
        else 
            return Application.Current.MainWindow.FindResource("EmptyTemplate") as DataTemplate; 
    } 
} 

Please refer the sample from the provided link. 


How to add spacing between Top most level rows only ? Children rows shouldn't have any spacing 
We regret to let you know that we are unclear about this requirement. If possible, please revert to us more details about this requirement with an image illustration. It will be helpful for us to understand the exact requirement and to provide a prompt solution. 
How to scroll to a specific source object ? 
You can scroll programmatically to particular cell using the ScrollInView method by passing row and column index. 

UG references :  
How to style a columns' top level cells ? 
We are little unclear about top level cells you have mentioned. However, we suspect your requirement is to apply style for the cells based on some conditions. Please refer the below given help documentation to apply conditionally styles for the cells and rows in SfTreeGrid.  
UG reference :  




Please let us know if we have misunderstood any of your requirement.  

Regards, 
Mohanram A. 




JO John January 17, 2022 03:30 PM UTC

<Window.Resources> 
    <Style TargetType="syncfusion:TreeGridExpander" > 
        <Setter Property="Template"> 
            <Setter.Value> 
                <ControlTemplate TargetType="syncfusion:TreeGridExpander"> 
                    <Grid Background="{TemplateBinding Background}" 
                  
SnapsToDevicePixels
="True"> 
                    </Grid> 
                </ControlTemplate> 
            </Setter.Value> 
        </Setter> 
    </Style> 
</Window.Resources>


it hides the expander but it also removes the checkbox column, so if I add another column before checkbox, checkbox column appears. But there is an empty space where expander was. TreeGrid is not completely moved to left.


MA Mohanram Anbukkarasu Syncfusion Team January 18, 2022 02:16 PM UTC

Hi John, 

We are little unclear about the issue you are facing in TreeGridCheckBoxColumn when using the provided solution. If possible, please revert to us with more details about the problem along with code snippets and image/video illustration. Otherwise try to reproduce the issue in the sample we have provided in our previous update and revert to us with modified sample and image/video illustration of the issue. It will be helpful for us to understand the exact issue and to provide a prompt solution.  

Regards, 
Mohanram A. 



JO John January 23, 2022 04:30 AM UTC

Please check the red marks, I want to remove this gapgap.png



MA Mohanram Anbukkarasu Syncfusion Team January 24, 2022 02:28 PM UTC

Hi John, 
 
You should create custom template for the TreeGridExpanderCell to achieve this requirement to completely remove the expand/collapse button. We have prepared a sample for this and it is available in the following link.  
 
 
Please have a look at this sample and let us know if you require further assistance from us.  
 
Regards, 
Mohanram A. 


Marked as answer
Loader.
Up arrow icon