Home > DeveloperSection > Forums > Fitting WPF DataGrid in a Grid control
Tanuj Kumar

Total Post:134

Points:940
Posted on    September-21-2013 6:53 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 728  View(s)
Rate this:

I have a DataGrid control inside a Grid control in one of my WPF windows.

<Grid>

  <Grid.RowDefinitions>

        <RowDefinition Height="Auto" />

        <RowDefinition Height="*" />

  </Grid.RowDefinitions>

  <SomeControl Grid.Row="0" />

  <DataGrid Grid.Row="1" VerticalScrollBarVisibility="Visible" VerticalAlignment="Stretch"/>

</Grid>

The problem is that when I add rows to the DataGrid it flows out of the containing window and its scroll bar remains inactive. How do I solve this problem and make the DataGrid's scroll bar to function correctly?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-21-2013 7:51 AM

Hi Tanuj,

You may try as follows

  <Grid>

            <Grid.RowDefinitions>

                <RowDefinition Height="Auto" />

                <RowDefinition Height="200" />

            </Grid.RowDefinitions>

            <DataGrid   Grid.Row="1" HorizontalAlignment="Left" Margin="54,65,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="382" VerticalScrollBarVisibility="Visible">

                <DataGrid.Columns>

                    <DataGridTextColumn Header="ID"/>

                    <DataGridTextColumn Header="ViewCount" />

                    <DataGridTextColumn Header="Title" />

                </DataGrid.Columns>

            </DataGrid>

        </Grid>

You need to provide some height to the DataGrid ,as you have RowDefinition Height="*" so the vertical Scrolbar was not active,try to give some height to the DataGrid.

Hope it will help you.


Don't want to miss updates? Please click the below button!

Follow MindStick