简体   繁体   中英

How to display a certain number of rows in a DataGrid? (C#/WPF)

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;
<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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM