33

I have a WPF DataGrid..

I want to freeze first column of that WPF DataGrid while horizontal scrlling..

My code is:

<DataGrid Name="dgQuestionTemplate" HorizontalAlignment="Left" Grid.Row="1" Width="870" HorizontalScrollBarVisibility="Auto" IsReadOnly="False">

            <DataGrid.Columns>                    
                <DataGridTextColumn Binding="{Binding ExamDate}" Header="Date" IsReadOnly="True" Width="90" />
                <DataGridTextColumn Binding="{Binding ExamName}" Header="Test Name" IsReadOnly="True" Width="195" />
                <DataGridTextColumn Binding="{Binding Batch}" Header="Batch" IsReadOnly="True" Width="100" />
                <DataGridTextColumn Binding="{Binding ExamTime}" Header="    Count Down  [Days: hr: min: sec]"  IsReadOnly="True" Width="*" />
            </DataGrid.Columns>

</DataGrid>
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
Avinash Singh
  • 2,697
  • 11
  • 44
  • 72

1 Answers1

54

Set the DataGrid's FrozenColumnCount="1".

<DataGrid FrozenColumnCount="1" Name="dgQuestionTemplate" HorizontalAlignment="Left" Grid.Row="1" Width="870" HorizontalScrollBarVisibility="Auto" IsReadOnly="False">

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.

DataGrid.FrozenColumnCount

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
Kurubaran
  • 8,696
  • 5
  • 43
  • 65