【问题标题】:How to display a certain number of rows in a DataGrid? (C#/WPF)如何在 DataGrid 中显示一定数量的行? (C#/WPF)
【发布时间】:2019-06-12 15:33:00
【问题描述】:

如何在 DataGrid 中显示一定数量的行?例如,只有前 15 个?

DataTable 有动态数据。我需要显示前 15 行。其余的也应该存在,但不显示。

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


DataTable csvTable = new DataTable();
...
CsvGrid.ItemsSource = csvTable.DefaultView;

【问题讨论】:

标签: c# wpf


【解决方案1】:
<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;
}

【讨论】:

    猜你喜欢
    • 2020-12-15
    • 2013-06-11
    • 2013-02-10
    • 2011-10-22
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多