Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: How to freeze column header in datagrid

How can I freeze my column header in a DataGrid in my WPF Window so that when I scroll down, the header is still visible.

[Edit]

Here's my XAML:

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Visible">
    <DataGrid Name="ModelsGrid" Background="Transparent" Foreground="Black"  RowHeight="30" ColumnWidth="100"  AutoGenerateColumns="False" ItemsSource="{Binding}">
        <DataGrid.Columns>
            <DataGridTextColumn Header="Property ID" Binding="{Binding Path=Id}" />
            <DataGridTextColumn Header="Name" Width="Auto" Binding="{Binding Path=PropertyName}" />
            <DataGridTextColumn Header="Description" Width="Auto" Binding="{Binding Path=Description}" />
            <DataGridTextColumn Header="Access" Width="Auto" Binding="{Binding Path=Accessibility}" />
            <DataGridTextColumn Header="Type" Width="Auto" Binding="{Binding Path=Type}" />
            <DataGridTextColumn Header="Category" Width="Auto" Binding="{Binding Path=Category}" />
        </DataGrid.Columns>
    </DataGrid>
</ScrollViewer>

[Edit]

I just had to get rid of the ScrollViewer and it's solved.

like image 396
for-each Avatar asked Apr 25 '13 06:04

for-each


People also ask

How to set the number of frozen columns in a DataGrid?

Set the Datagrid's FrozenColumnCount = "1". Frozen columns are columns that are always displayed and cannot be scrolled out of visibility. Frozen columns are always the leftmost columns in display order. You cannot drag frozen columns into the group of unfrozen columns or drag unfrozen columns into the group of frozen columns.

Is it possible to freeze the last column in WPF DataGrid?

EDIT: To clarify, it will still need to be the first column that is frozen, but it'll be frozen to the right side. Sorry, something went wrong. Sorry, something went wrong. I tried this alternative solution you have mentioned @miloush . Last column can be freezed.But then so many other issues are rising compared to normal WPF data-grid behavior.

How do I freeze a column on the left?

The frozen columns stay static on top of the horizontal scrolling. To freeze a column on the left, the user has to drag the left frozen columns separator. Once there is a frozen column, you can freeze other columns by dragging their headers behind the frozen columns separator.

How do I disable the freezing of a column in radgridview?

To disable the freezing of a column, just set the CanUserFreezeColumns to False (as shown in Example 2) and the frozen columns separator will disappear. You can set the FrozenColumnsSplitterVisibility property of the RadGridView control in order to hide/show the left frozen columns splitter.


1 Answers

I just had to get rid of the ScrollViewer and it's solved.

like image 121
for-each Avatar answered Sep 27 '22 18:09

for-each