---
title: "Fitting WPF DataGrid in a Grid control"  
description: "Fitting WPF DataGrid in a Grid control"  
author: "Anonymous User"  
published: 2013-09-21  
updated: 2013-09-21  
canonical: https://www.mindstick.com/forum/1465/fitting-wpf-datagrid-in-a-grid-control  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# Fitting WPF DataGrid in a Grid control

I have a DataGrid [control inside](https://www.mindstick.com/forum/136/how-to-find-control-inside-of-repeater) a [Grid](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid) control in one of my [WPF](https://www.mindstick.com/forum/304/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](https://www.mindstick.com/forum/160518/how-to-add-rows-to-datatable-in-dot-net-using-c-sharp) to the DataGrid it flows out of the containing [window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript) and its scroll bar remains inactive. How do I [solve this problem](https://answers.mindstick.com/qa/94681/my-google-assistant-shows-completely-different-search-results-from-what-i-ask-how-can-i-solve-this-problem) and make the DataGrid's scroll bar to [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) correctly?

## Replies

### Reply by Sumit Kesarwani

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.


---

Original Source: https://www.mindstick.com/forum/1465/fitting-wpf-datagrid-in-a-grid-control

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
