Articles in this section
Category / Section

How to skip the certain columns from AutoRowHeight support in WPF DataGrid (SfDataGrid)?

1 min read

WPF DataGrid (SfDataGrid) allows you the AutoRowHeight support based on cell content by using QueryRowHeight event. You can avoid certain columns from AutoRowHeight support using GridRowSizingOptions.ExcludeColumns property like below code example.

C#

public ExlucedColumnsList ExlucedColumnsList
{
     get { return (ExlucedColumnsList)GetValue(ExlucedColumnsListProperty); }
     set { SetValue(ExlucedColumnsListProperty, value); }
}
 
public static readonly DependencyProperty ExlucedColumnsListProperty = DependencyProperty.Register("ExlucedColumnsList", typeof(ExlucedColumnsList), typeof(QueryRowHeightBehaviour), new PropertyMetadata(null));
 
GridRowSizingOptions gridRowResizingOptions = new GridRowSizingOptions();
double Height = double.NaN;
 
protected override void OnAttached()
{
     this.AssociatedObject.QueryRowHeight += AssociatedObject_QueryRowHeight;
     gridRowResizingOptions.ExcludeColumns = ExlucedColumnsList;
}
 
//QueryRowHeight event
void AssociatedObject_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
     if (this.AssociatedObject.IsTableSummaryIndex(e.RowIndex))
     {
                e.Height = 40;
                e.Handled = true;
     }
     else if (this.AssociatedObject.GridColumnSizer.GetAutoRowHeight(e.RowIndex, gridRowResizingOptions, out Height))
     {
         if (Height > this.AssociatedObject.RowHeight)
         {
             e.Height = Height;
             e.Handled = true;
         }
     }
}

XAML

<Syncfusion:SfDataGrid x:Name="datagrid" ItemsSource="{Binding GDCSource}">                      
            <interactivity:Interaction.Behaviors>
                <local:QueryRowHeightBehaviour>
                    <local:QueryRowHeightBehaviour.ExlucedColumnsList>
                        <local:ExlucedColumnsList>
                            <sys:String>EmployeeName</sys:String>
                            <sys:String>EmployeeAge</sys:String>
                        </local:ExlucedColumnsList>
                    </local:QueryRowHeightBehaviour.ExlucedColumnsList>
                </local:QueryRowHeightBehaviour>
            </interactivity:Interaction.Behaviors>
            <Syncfusion:SfDataGrid.Columns>
                <Syncfusion:GridTextColumn MappingName="EmployeeName"  TextWrapping="Wrap" AllowFiltering="True"/>
                <Syncfusion:GridTextColumn MappingName="EmployeeAge"  TextWrapping="Wrap" AllowFiltering="True"/>
                <Syncfusion:GridTextColumn MappingName="EmployeeArea"  TextWrapping="Wrap" AllowFiltering="True"/>
                <Syncfusion:GridTextColumn MappingName="EmployeeGender"  TextWrapping="Wrap" AllowFiltering="True"/>
            </Syncfusion:SfDataGrid.Columns>
</Syncfusion:SfDataGrid>

View sample in GitHub.

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