0

Good day! I have datagrid ,buttons Add\Remove and i want to make vertical scroll rows, when the number of lines increases.

I try this on DataGrid:

VerticalScrollBarVisibility="Visible"

But scroll is inactive. Full code:

<Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>         
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>

    <GroupBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4">
        <GroupBox.Header>
            <TextBlock Text="Tables'}"
           FontWeight="Bold"
           FontStyle="Italic" />
        </GroupBox.Header>
            <TabControl Grid.Row="0" Grid.RowSpan="4">
                <TabItem  Header="Table 1" >
                    <StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="0">
                        <ToolBar   Height="22">

                            <Button x:Name="btAdd"  Click="btAdd_Click"  Height="22"
                    ToolTip="Add">                                              
                            </Button>

                            <Button x:Name="btDel"  Click="btDel_Click"  Height="22"
                    ToolTip="Delete">                               
                            </Button>
                        </ToolBar>

                        <DataGrid AutoGenerateColumns="False" 
                            Name="dgTable"     
                            VerticalScrollBarVisibility="Visible"
                            CanUserAddRows="False"
                            CanUserDeleteRows="False"
                            IsEnabled="True"
                            IsReadOnly="False"
                            ItemsSource="{Binding ObjectViewModel.RowColl,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">

                            <DataGrid.Columns>
                                ....
                            </DataGrid.Columns>
                        </DataGrid>                    
                    </StackPanel>                  
                </TabItem>
            </TabControl>
        </GroupBox>
    </Grid>
</Grid>

But when i add too much rows at datagrid- nothing happens- i can not scroll rows. Please, tell me how to make datagrid scrollable.

Thank you!

Eugene Podskal
  • 10,270
  • 5
  • 31
  • 53
user2545071
  • 1,408
  • 2
  • 24
  • 46

2 Answers2

2
  <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
  <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
  <Setter Property="ScrollViewer.CanContentScroll" Value="true" />
Jayasri
  • 237
  • 1
  • 11
1

Remove the stackpanel height property and give maxheight property to datagrid

Justin CI
  • 2,693
  • 1
  • 16
  • 34