I have a DataGrid
that when I load the data into it, I cannot scroll down
So this is how the DataGrid
looks like
As you can see there are rows at the bottom that I can't see
Even though when I try to put the highlight below I still can't see the rows below.
The DataGrid
is auto-generated from a list. I have tried setting the VerticalScrollBarVisibility
& HorizontalScrollBarVisibility
but I still can't see the other data.
Here is my XAML code for the datagrid
<StackPanel Orientation="Vertical" Margin="0,0,0,0" Grid.Row="1">
<DataGrid
x:Name="dgvAttendance"
Margin="0,20"
CanUserSortColumns="True"
CanUserAddRows="False" SelectedIndex="0" AlternationCount="2" AutoGenerateColumns="True" SelectionMode="Single" EnableColumnVirtualization="True" IsReadOnly="True" ScrollViewer.CanContentScroll="False" CanUserReorderColumns="False" CanUserResizeColumns="False" HeadersVisibility="All" CanUserResizeRows="False" PreviewMouseWheel="DgvAttendance_PreviewMouseWheel" />
<Button
x:Name="btnExportExcel"
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Width="110"
ToolTip="Resource name: MaterialDesignRaisedLightDarkButton" Margin="15,10" Content="Export File" HorizontalAlignment="Right" Click="BtnExportExcel_Click" />
</StackPanel>
There is also a button on the datagrid that I can't see
Here is my code that Loads the dataGrid
public void Main()
{
actuals = NewActual(@"C:\Users\IT\Desktop\Sample\SampleActual.dat");
emps = GetEmp();
var final = (from t1 in actuals
join t2 in emps on t1.ID equals t2.ID
where t1.ID == t2.ID
orderby t2.ID
select new
{
t1.ID,
t2.In,
t1.ActualLog
});
dgvAttendance.ItemsSource = final.ToList();
}
Any ideas why I am not able to scroll down and see the button below the DataGrid
? Thanks
As suggestion from Polly
I just wrapped my StackPanel with a ScrollViewer so it looks like this
<ScrollViewer Grid.Row="1">
<StackPanel Orientation="Vertical" Margin="0,0,0,0" >
<DataGrid
x:Name="dgvAttendance"
Margin="0,20"
CanUserSortColumns="True"
CanUserAddRows="False" SelectedIndex="0" AlternationCount="2" AutoGenerateColumns="True" SelectionMode="Single" EnableColumnVirtualization="True" IsReadOnly="True" ScrollViewer.CanContentScroll="False" CanUserReorderColumns="False" CanUserResizeColumns="False" HeadersVisibility="All" CanUserResizeRows="False" PreviewMouseWheel="DgvAttendance_PreviewMouseWheel" >
</DataGrid>
<Button
x:Name="btnExportExcel"
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Width="110"
ToolTip="Resource name: MaterialDesignRaisedLightDarkButton" Margin="15,10" Content="Export File" HorizontalAlignment="Right" Click="BtnExportExcel_Click" />
</StackPanel>
<!-- Stack for Datagrid Ends Here -->
</ScrollViewer>