0

How to display a certain number of rows in a DataGrid? For example, only the first 15?

DataTable has dynamic data. I need to display the first 15 lines. And the rest should also be present, but not displayed.

<DataGrid x:Name="CsvGrid" ColumnWidth="*" ItemsSource="{Binding csvTable}">


DataTable csvTable = new DataTable();
...
CsvGrid.ItemsSource = csvTable.DefaultView;
MiT
  • 145
  • 3
  • 10

1 Answers1

0
<DataGrid x:Name="CsvGrid" ColumnWidth="*" LoadingRow="CsvGrid_LoadingRow" ItemsSource="{Binding csvTable}" />

private void CsvGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
    e.Row.Header = (e.Row.GetIndex()+1).ToString();
    if(e.Row.GetIndex() > _showRows - 1) e.Row.Visibility = Visibility.Hidden;
}
MiT
  • 145
  • 3
  • 10