Dhinesh
Dhinesh

Reputation: 181

How to avoid adjusting the width, height of rows and columns in Datagrid by user

How to avoid adjusting the width, height of rows and columns in DataGrid by user

Here is my XAML Code:

<DataGrid 
   Name="MarkDG" 
   ItemsSource="{StaticResource Marks}" 
   IsReadOnly="True" 
   HorizontalAlignment="Left" 
   Margin="323,179,0,0" 
   VerticalAlignment="Top" 
   AutoGenerateColumns="False" 
   ColumnWidth="150" 
   HeadersVisibility="Column" 
   VerticalScrollBarVisibility="Auto" 
   FrozenColumnCount="1">
   <DataGrid.Columns>
      <DataGridTextColumn Binding="{Binding Path=StuNo}" Header="Student No" />
      <DataGridTextColumn Binding="{Binding Path=MarkSet}" Header="Mark Obtained"/>
   </DataGrid.Columns>
</DataGrid>

Initially DataGrid appears to be
enter image description here
But the user can move the DataGrid as shown below
enter image description here
How to avoid such situation?

Upvotes: 1

Views: 87

Answers (1)

dkozl
dkozl

Reputation: 33364

If you want to disable column and/or row resizing by the user set CanUserResizeColumns="False" and CanUserResizeRows="False" against you DataGrid:

<DataGrid ... CanUserResizeColumns="False" CanUserResizeRows="False"/>

Upvotes: 3

Related Questions