How can I enable scrollbars in WPF Datagrid?

When I run the following code> Datagrid Northwind WPF Toolkit from in this article , I get a datagrid, but there is no scrolling , and therefore, the user can only see part of the datagrid. I am using the latest version in March 2009.

What do I need to specify for WPF Datagrid to have scrollbars?

I tried putting the datagrid in a ScrollViewer, but that didn't help.

XAML:

<Window x:Class="TestDataGrid566.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit" Title="Window1" Height="600" Width="800"> <StackPanel> <toolkit:DataGrid x:Name="TheDataGrid" AutoGenerateColumns="True"/> </StackPanel> </Window> 

background code:

 using System.Linq; using System.Windows; using TestDataGrid566.Model; namespace TestDataGrid566 { public partial class Window1 : Window { public Window1() { InitializeComponent(); NorthwindDataContext db = new NorthwindDataContext(); var customers = from c in db.Customers select c; TheDataGrid.ItemsSource = customers; } } } 
+53
scroll wpf datagrid
Mar 23 '09 at 14:10
source share
6 answers

Place the DataGrid in the Grid , DockPanel , ContentControl or directly in the Window . The vertically oriented StackPanel will give its children any vertical space they ask for, even if it means that it is out of sight.

+88
Mar 23 '09 at 14:28
source share

WPF4

 <DataGrid AutoGenerateColumns="True" Grid.Column="0" Grid.Row="0" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"> </DataGrid> 

with: <ColumnDefinition Width="350" /> and <RowDefinition Height="300" /> works fine.

Scroll bars are not displayed using <ColumnDefinition Width="Auto" /> and <RowDefinition Height="300" /> .

Also works great with: <ColumnDefinition Width="*" /> and <RowDefinition Height="300" /> if it is nested in an external <Grid> .

+44
Feb 08 2018-11-18T00:
source share

If any of the parent containers of the RowDefinition Height is set to "Auto" also traffic jams for scroll bars

Alternatively, you can set the height to "*"

What happened in my case.

+15
May 25 '15 at 7:06
source share

Adding MaxHeight and VerticalScrollBarVisibility="Auto" to the DataGrid solved my problem.

+7
May 12 '16 at 9:27
source share

Add a grid with a specific height and width for columns and rows. Then add a ScrollViewer and inside it add a dataGrid.

+1
Jun 03 '16 at 14:21
source share

In my case, I had to set MaxHeight and replace IsEnabled="False" with IsReadOnly="True"

0
Mar 27 '19 at 12:07 on
source share



All Articles