Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I enable scrollbars on the WPF Datagrid?

When I run the following Northwind WPF Toolkit Datagrid code from this article, I get a datagrid, but there are no scrollbars and hence the user can only see part of the datagrid. I am using the newest version March 2009.

What do I need to specify so that the WPF Datagrid has 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> 

code-behind:

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;         }     } } 
like image 441
Edward Tanguay Avatar asked Mar 23 '09 14:03

Edward Tanguay


People also ask

How do I add a ScrollBar in WPF?

There are two predefined elements that enable scrolling in WPF applications: ScrollBar and ScrollViewer. The ScrollViewer control encapsulates horizontal and vertical ScrollBar elements and a content container (such as a Panel element) in order to display other visible elements in a scrollable area.

How do I add a vertical ScrollBar in WPF?

VerticalAlignment="Stretch" ), but on the small screen, automatically display the vertical scroll bar when needed.

How do I add a ScrollBar to a label?

Place a panel in location where you want the label to be, set it's AutoScroll property to true. Then place the label in the panel, anchor it and set it's AutoSize property to true. This will make the panel provide the scroll bars if the label's text extends outside of the panel.


1 Answers

Put the DataGrid in a Grid, DockPanel, ContentControl or directly in the Window. A vertically-oriented StackPanel will give its children whatever vertical space they ask for - even if that means it is rendered out of view.

like image 185
Kent Boogaart Avatar answered Sep 29 '22 07:09

Kent Boogaart