Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/22/15 19:49:18 (9 years ago)
Author:
gkronber
Message:

#2473: improvements as suggested by abeham https://dev.heuristiclab.com/trac.fcgi/ticket/2473#comment:3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionTableView.cs

    r13036 r13054  
    123123
    124124    protected override void UpdateColumnHeaders() {
     125      string[] colNames = base.Content.ColumnNames.ToArray();
     126      int colCount = colNames.Length;
    125127      for (int i = 0; i < dataGridView.ColumnCount; i++) {
    126         if (i < base.Content.ColumnNames.Count())
    127           dataGridView.Columns[i].HeaderText = base.Content.ColumnNames.ElementAt(i);
     128        if (i < colCount)
     129          dataGridView.Columns[i].HeaderText = colNames[i];
    128130        else
    129131          dataGridView.Columns[i].HeaderText = "Column " + (i + 1);
    130132      }
    131133
    132       HashSet<string> visibleColumnNames = new HashSet<string>(dataGridView.Columns.OfType<DataGridViewColumn>()
    133        .Where(c => c.Visible && !string.IsNullOrEmpty(c.HeaderText) && GetNumberOfDistinctValues(c.HeaderText) > 1).Select(c => c.HeaderText));
     134      HashSet<string> visibleColumnNames = new HashSet<string>(
     135        dataGridView.Columns.OfType<DataGridViewColumn>()
     136       .Where(c => c.Visible)
     137       .Where(c => !string.IsNullOrEmpty(c.HeaderText))
     138       .Where(c => !IsConstant(c.HeaderText))
     139       .Select(c => c.HeaderText));
    134140
    135141      for (int i = 0; i < dataGridView.ColumnCount; i++) {
     
    138144    }
    139145
    140     // returns the number of different values for the parameter or result in the RunCollection
    141     private int GetNumberOfDistinctValues(string columnName) {
     146    // returns true when all values in the column are the same (missing values are included in the count)
     147    private bool IsConstant(string columnName) {
    142148      Func<IRun, string, string> GetStringValue = (IRun r, string colName) => {
    143149        // also include missing values in the count
    144         if (r.Parameters.ContainsKey(colName)) return r.Parameters[colName].ToString();
    145         if (r.Results.ContainsKey(colName)) return r.Results[colName].ToString();
     150        IItem v = null;
     151        if (r.Parameters.TryGetValue(colName, out v)) return v.ToString();
     152        if (r.Results.TryGetValue(colName, out v)) return v.ToString();
    146153        return string.Empty;
    147154      };
    148       return Content.Select(r => GetStringValue(r, columnName)).Distinct().Count();
     155
     156      var firstRun = Content.First();
     157      string firstValue = GetStringValue(firstRun, columnName);
     158      return Content.Skip(1).All(run => firstValue == GetStringValue(run, columnName));
    149159    }
    150160
Note: See TracChangeset for help on using the changeset viewer.