我有一个绑定到对象列表的WPF DataGrid。 正在显示的数据基本上是一天中每小时一班航班抵达&班次的表格。在WPF DataGrid列中查找最大值和最小值
的XAML为DataGrid是:
<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,我绑定到网格: Traf ficGrid.ItemsSource = fltrowsList;
我想找到每个班级的最大和最小值,然后突出显示列中的这两个单元格。但是,我很难理解如何遍历数据网格的每一列,并找到最大值和最小值。已经尝试了几种类似于以下的方法(迭代一列),但都没有工作。
for (nCol = 1; nCol < 13; nCol++)
{
for (nRow = 0; nRow < 24; nRow++)
{
var rr = TrafficGrid.Columns[nCol].GetCellContent(TrafficGrid.CurrentCell(nRow));
等
也许我不是在正确的道路这种思维。任何援助将不胜感激。
Thanx的建议。我会尝试并报告。不过,我将会旅行一段时间,所以我可能会在几天后发布回复。 – user2000900