Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Freeze First Column of WPF DataGrid [duplicate]

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> 
like image 497
Avinash Singh Avatar asked Aug 31 '13 09:08

Avinash Singh


People also ask

How to freeze a column in DataGrid WPF?

To freeze columns, set the FrozenColumnCount property. The leftmost columns specified by the FrozenColumnCount number will become frozen. For example, if you set the FrozenColumnCount to 2, the two left columns in the display are frozen.

How do I freeze a column in DataGrid?

To freeze a column using the designer ) on the upper-right corner of the DataGridView control, and then select Edit Columns. Select a column from the Selected Columns list. In the Column Properties grid, set the Frozen property to true .

How do I make DataGrid read only?

To make a column read-only programmaticallySet the DataGridViewColumn. ReadOnly property to true .


1 Answers

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

like image 79
Kurubaran Avatar answered Sep 18 '22 20:09

Kurubaran