繁体   English   中英

在WPF DataGrid列中查找最大值和最小值

[英]Find max and min values in a WPF DataGrid column

我有绑定到对象列表的WPF DataGrid。 显示的数据基本上是一天中每个小时航班到达和离开的表格。

数据网格的XAML是:

 <DataGrid Name="TrafficGrid" Margin="20,10,10,0"  Grid.Row="1" Height="550"
                  VerticalAlignment="Top"
                  Background="Beige" RowBackground="Beige"
                  HorizontalContentAlignment="Center"
                  SelectionMode="Single"
                  SelectionUnit="Cell">
 </DataGrid>

对象声明为:

public class fltgridCell
        {
            public int cellValue { get; set; }
            public int highlight { get; set; }
        }

列表声明为:

public List<fltgridRow> fltrowsList = new List<fltgridRow>();

 public class fltgridRow
        {
            public string hour { get; set; }
            public fltgridCell cmclDep { get; set; } = new fltgridCell() {cellValue = 0, highlight = 0};
            public fltgridCell cmclArr { get; set; } = new fltgridCell( ) { cellValue = 0, highlight = 0 };
            public fltgridCell corpDep { get; set; } = new fltgridCell( ) { cellValue = 0, highlight = 0 };
            public fltgridCell corpArr { get; set; } = new fltgridCell( ) { cellValue = 0, highlight = 0 };
            public fltgridCell gaDep { get; set; } = new fltgridCell( ) { cellValue = 0, highlight = 0 };
            public fltgridCell gaArr { get; set; } = new fltgridCell( ) { cellValue = 0, highlight = 0 };
         }

从数据库中检索每种航班的计数并填充fltrowsList之后,我便绑定到网格:TrafficGrid.ItemsSource = fltrowsList;

我想找到每个航班类别的最大值和最小值,然后在列中突出显示这两个单元格。 但是,我对如何遍历数据网格的每一列并找到最大值和最小值感到困惑。 尝试了几种与以下类似的方法(在专栏中重复),但没有任何效果。

for ( nCol = 1; nCol < 13; nCol++ )
{
    for ( nRow = 0; nRow < 24; nRow++ )
    {
         var rr = TrafficGrid.Columns[nCol].GetCellContent(TrafficGrid.CurrentCell(nRow) );

等等

也许我没有以正确的方式考虑这个问题。 任何帮助将不胜感激。

由于您的单元格类中已经具有高亮属性,因此可以在此之前确定最小值和最大值。 进行数据库查询并执行LINQ查询,如var fClassMax = databaseResult.Max( t => t.flightClass)var fClassMin = databaseResult.Min( t => t.flightClass) ,那么您就需要设置值并设置hightlight属性值匹配的地方。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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