0
votes

I have a WPF DataGrid that is bound to a list of objects. The data being displayed is basically a table of flight arrivals & departures by each hour of the day.

The XAML for the datagrid is:

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

The object declaration is:

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

The list declaration is:

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

After I retrieve the count of each type of flight from the database and populate fltrowsList , I bind to the grid: TrafficGrid.ItemsSource = fltrowsList;

I want to find the max and min values for each class of flight, and then highlight those two cells in the column. However, I am stumped as to how to iterate through each column of the datagrid and find the max and min values. Have tried several approaches similar to the following (iterate down a column), but none work.

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

etc.

Maybe I am not thinking of this in the right way. Any assistance would be greatly appreciated.

1

1 Answers

0
votes

As you already have a highlight property in your cell class, you could determine the min and max value before. Take the database result an do a LINQ query like var fClassMax = databaseResult.Max( t => t.flightClass) and var fClassMin = databaseResult.Min( t => t.flightClass), then you have the values and need the set the hightlight property the where the values matches.