Articles in this section

How to Adjust width of WPF DataGrid (SfDataGrid) when hiding columns using ColumnChooser?

In WPF DataGrid (SfDataGrid) while hiding the columns using ColumnChooser, empty space will be added to the right side of the DataGrid. You can avoid this by adjusting the width of the DataGrid while hiding columns using ColumnChooser.

 

this.dataGrid.Columns.Changed += OnColumns_Changed;
 
private void OnColumns_Changed(object sender, EventArgs e)
{
    double width = 0;
    foreach(var column in this.dataGrid.Columns)
    {
        width += column.IsHidden ? 0 : column.ActualWidth;
    }
 
    this.dataGrid.Width = width;
}

 

Take a moment to peruse the documentation, where you can find about column chooser in SfDataGrid, with code examples.

You can download the example from GitHub

 

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