Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stretching columns to fill all available space of DataGrid

Is it possible to stretch columns or the last column to fill all the available space of the data grid?

<DataGrid Grid.Row="0" AutoGenerateColumns="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name="dataGrid1"   ItemsSource="{Binding Customers}" />

My columns are Auto generated.

like image 971
Night Walker Avatar asked Jul 29 '11 16:07

Night Walker


1 Answers

Yes, I think you are looking for the AutoSizeMode property.

int n = grid.Columns.Count;
grid.Columns[n].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

Edit: Try setting the width to "*" as seen below. You'll have to do this in the code if your columns are auto-generated.

<DataGrid>
  <DataGrid.Columns>
    <DataGridTextColumn Width="Auto" />
    <DataGridTextColumn Width="*" />
  </DataGrid.Columns>
</DataGrid>
like image 122
user807566 Avatar answered Oct 07 '22 11:10

user807566