Hello,
I put a datagrid in a window. The size of the window is smaller than the size of the datagrid, but there is no scrollbar turned on automatically.
How could I turn on the scrollbar?
Thanks.
Check the layout properties for the XamDataGrid in your layout. Is it in a Grid? Is the Grid set to Auto Size Width and Height and Vertical and Horizontal Alignment set to Stretch? Are those same properties for the XamDataGrid also set to Width=Auto and Height=Auto and VerticalAlignment=Stretch and HorizontalAlignment=Stretch. These are the default settings. So if your XAML does not have any of these properties set, then you should be OK.
If the element is set to be positioned VerticalAlignment to Top and HorizontalAlignment to Left, then the element (such as the XamDataGrid) will span to the right and to the bottom. However, if they are set to Stretch with Auto Width and Height, the grid will span to fit its container. And the scrollbars will automatically appear.
Additionally, make sure that VerticalScrollbarVisibility and HorizontalScrollbarVisibility are set to Auto or Visible (or not set at all in your XAML).
If this does not solve your issue, paste the XAML here that we might see what is going on.
Thanks!
Hi
Did you manage to resolve this issue ? Did the solution provided by Curtis help ? Let me know if you have further questions. Thanks.
Thanks for your reply.
I haven't resolved the problem yet. When I put the datagrid in a stackpanel, the scrollbars appeared automatically. But the scrollbars didn't appear when I put the datagrid in a canvas. I need to put the datagrid in the canvas for some overlay reasons. I tried to put the canvas in a scrollviewer, but it didn't work.
Is there any idea how I could make the datagrid scrollbars appear in canvas?
That does not seem like default behaviour. Can you paste your xaml here or attach a sample for us to check ? Thanks.
Please see my sample code below:
<Window x:Class="DataGrid.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:igEditors="http://infragistics.com/Editors" xmlns:local="clr-namespace:DataGrid.UserControls" Title="DataGrid" Height="300" Width="800"> <Grid> <Canvas>
<local:CategoryControl Panel.ZIndex="1" Canvas.Left="5" Canvas.Top="5" x:Name="categoryControl" HorizontalContentAlignment="Left" BorderThickness="1" HorizontalAlignment="Left" /> <igDP:XamDataGrid Canvas.Left="5" Canvas.Top="33" Panel.ZIndex="0" x:Name="XamDataGrid1" GroupByAreaLocation="None"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" SelectionTypeRecord="Extended" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings AllowEdit="True" CellClickAction="SelectCell" LabelClickAction="SelectField" /> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Settings> <igDP:FieldLayoutSettings LabelLocation="SeparateHeader" /> </igDP:FieldLayout.Settings> <igDP:FieldLayout.Fields> <igDP:Field Name="EmployeeNumber"> <igDP:Field.Settings> <igDP:FieldSettings CellWidth="150"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="FirstName"> <igDP:Field.Settings> <igDP:FieldSettings CellWidth="130"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="LastName"> <igDP:Field.Settings> <igDP:FieldSettings CellWidth="130"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Age"> <igDP:Field.Settings> <igDP:FieldSettings CellWidth="100"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Gender"> <igDP:Field.Settings> <igDP:FieldSettings CellWidth="100"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Salary"> <igDP:Field.Settings> <igDP:FieldSettings CellWidth="100"/> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Pension"> <igDP:Field.Settings> <igDP:FieldSettings CellWidth="100"/> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Canvas> </Grid> </Window>
Some panels will not size to the container it is in. If you were to put the XamDataGrid in a Grid you would not have this problem. I recommend you do not use Canvas. Canvas doesn't work very well with auto-sizing scenarios. Canvas is more of a panel where you simply place objects and they stay where they are put. Objects in a Canvas also do not size to the container size but size to their own content. So the XamDataGrid is sizing to it internal content. To see scrollbars you need the XamDataGrid to size to its container (like a window or a Grid in a Window).
To answer your question about Canvas...
What are you trying to accomplish by using Canvas? There may be another solution. Canvas is not going to get you want you want.
If you must use Canvas, then you must give the XamDataGrid a hard coded Width and Height. Then you will see scrollbars appear. If you want to support some kind of auto-sizing scenario for an element in a Canvas, you must programmatically set the Width and Height yourself.
Thanks,
Thanks. This resolved the scrollbar and cell merge problems.
There is a built-in way in the grid to achieve what you are doing. Please see the below blog post :-
http://blogs.infragistics.com/blogs/alex_fidanov/archive/2010/06/02/howto-common-headers-in-the-xamdatagrid.aspx
This should resolve your issue.
Please find the current screenshot attached. The screenshot is using some of your sample data.
As you can see from the screenshot, the horizontal scrollbar only applies to the datagrid. I need the group headings (ID, PersonalDetails, and PayPackage) to be sync with the labels. So, I need the horizontal scrollbar to apply to the group headings as well.
To have items overlay each other, you can either give them a negative margin, or apply a TranslateTransform in the RenderTransform property. So if you have an item above another in a Grid or StackPanel and you need it to overlay the item below it, give that item a negative bottom margin or offset the Y TranslateTransform with a positive number.
As far as the scrollbars and the XamDataGrid Group Headers issue, would you provide a screenshot of what you are seeing and what you wish the desired results to be?
Thank you!
I must use canvas, because I need to use overlay to make the group headings to rotate above the XamDataGrid. I found canvas is the only way to make overlay. If you know another solution, please let me know.
I have tried to hard code the Width and Height for the XamDataGrid, the scrollbars appeared for the XamDataGrid. But the scrollbars didn't apply to the group headings. I developed my group headings control, because I couldn't merge the cells in XamDataGrid. Is there any way to apply the scrollbars to both XamDataGrid and group headings?