Missing scrolling in Datagrid

Oct 19, 2008 at 5:16 PM
Somehow I can not make the DataGrid to show the ScrollBar. Funnily, in another window the ScrollBar works just fine. In the former case DataGrid sits in the window grid, while in the latter it is in the TabItem.$0$0$0$0what can be a problem here?$0
Oct 20, 2008 at 2:09 AM
Hi, snovik

As long as I know, we need to fix the size of the DataGrid to get the scrollbar. Just make sure, may be another problem!
Oct 20, 2008 at 10:23 AM
for the time being I am using MaxHeight which is not supergood but gives me time to wait until the release
Oct 20, 2008 at 10:53 PM
The appearance of scrollbars (or lack thereof) can often  be a result of the layout choices you have made in other parts of the UI and how those elements relate to the data grid and/or its parents.  If you have a "proper" layout the automatic scroll bar visibility settings (the default settings) do work.  If you always want the scroll bars you can explicitly set the visibility to Visible.  Or you can post your layout and someone can help you figure out why the DataGrid does not know how large its container is. 

Set the visibility manually:

<dg:DataGrid VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Hidden" >
...
</dg:DataGrid>

Default settings are:

<dg:DataGrid VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" >
...
</dg:DataGrid>
Oct 21, 2008 at 3:43 AM
well, I tripple checked. I have a bunch of windows with some textblocks and textbox on top and datagrid at the bottom. The master element in the window is grid without any settings. window can be set both to sizetocontent or fixed height or size to width - does not matter. in all cases datagrid goes way below the size of the window.
Oct 21, 2008 at 10:52 PM
I would suggest using row/column definitions in your main grid and making use of the special dynamic size settings ("*" and "Auto").  The "Auto" operator means that the row/column will be as large as it needs to be to accommodate the tallest/widest element in it.  The "*" operator means that the row/column will take up the remaining vertical/horizontal space in the grid.  You can further modify the "*" operator to give it a fixed percentage of the height/width or combine multiple "*" operators to have them share space equally. You can also use max and min values in conjunction with the "*" operator to get all kinds of interesting behavior.   I would highly suggest playing around with these settings until you find the desired behavior for your application. 

In the example below the DataGrid should be as tall as the grid that contains it minus the space occupied by the first and third rows.  If the DataGrid is too large it will automatically show the scroll bars and give you the behavior you're seeking without pushing the third row out of view.  Understanding how these special sizes work and separating your UI into smaller parts should allow you to get a layout that looks good even when the windows change size and uses minimal manual size settings.

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" MinHeight="100" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="0" >
                        <TextBlock Text="Put stuff here." />
                    </StackPanel>
                    <dg:DataGrid Grid.Row="1" >
                    </dg:DataGrid>
                    <TextBlock Grid.Row="2" Text="This is a footer." />
                </Grid>

Oct 22, 2008 at 10:09 AM
surely I tried all of options.  I could post a screenshot if I could. The grid simply goes under the window which also has a MaxHeight set.

In any case without auto or * the grid's rows and columns have equal sizes which should not prevent DataGrid from showing scroll bar in particular when the main window size is fixed
Oct 22, 2008 at 8:07 PM
I can assure you that the problem is a result of how you are laying out the window and not anything specific to the datagrid.  Again if you want someone to help fix your layout you would need to provide what you have so far.  Also I'm not sure what you mean about grids.  Without any row or column definitions in the grid there is only one row and one column that will contain all child elements of the grid in a big pile.  One of the fundamentals of UI design is to create regions that will host your controls.  That is exactly what the grid is for and the direction I'm trying to convey.  Get a basic layout that works first then add your controls and code.  Hope that helps...
May 12, 2009 at 10:06 PM

I noticed that when my grid is into a StackPanel scroll is missing but if I replace a StackPanel with Border scroll bars work well. Is that behavior normal?

Jul 6, 2009 at 4:30 PM

12055, your suggestion about using Row/Col definitions works