Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17565 for branches


Ignore:
Timestamp:
05/28/20 09:35:39 (4 years ago)
Author:
chaider
Message:

#2971 fixed bug in gridview in IntervalCollectionView

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/IntervalCollectionView.cs

    r17564 r17565  
    2222
    2323using System.Windows.Forms;
     24using HeuristicLab.Common;
    2425using HeuristicLab.MainForm;
    2526using HeuristicLab.MainForm.WindowsForms;
     
    7778      dataGridView.Rows.AddRange(rows);
    7879
    79       int j = 0;
     80      var j = 0;
    8081      foreach (var variableInterval in Content.GetVariableIntervals()) {
    8182        dataGridView.Rows[j].HeaderCell.Value = variableInterval.Item1;
     
    100101
    101102    private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) {
    102       var key = dataGridView.Rows[e.RowIndex].HeaderCell.Value.ToString();
    103 
    104103      if (e.ColumnIndex < 0 || e.RowIndex < 0) return;
    105104
    106       var lowerBound = e.ColumnIndex == 0 ? double.Parse(dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()) : Content.GetInterval(key).LowerBound;
    107       var upperBound = e.ColumnIndex == 1 ? double.Parse(dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()) : Content.GetInterval(key).UpperBound;
     105      var key = dataGridView.Rows[e.RowIndex].HeaderCell.Value.ToString();
     106      var gridData = dataGridView[e.ColumnIndex, e.RowIndex].Value;
     107      //Cells maybe null during initialization
     108      var lowerBound = Content.GetInterval(key).LowerBound;
     109      var upperBound = Content.GetInterval(key).UpperBound;
     110
     111      //Check if the input data is a string (user-defined input)
     112      //if so parse the toString() of the value, otherwise do a hard-cast
     113      //to not loose the double precision
     114      double parsedValue;
     115      if (gridData is string) {
     116        parsedValue = double.Parse(gridData.ToString());
     117      } else {
     118        parsedValue = (double) gridData;
     119      }
     120
     121      if (e.ColumnIndex == 0) lowerBound = parsedValue;
     122      if (e.ColumnIndex == 1) upperBound = parsedValue;
     123
     124      var newInterval = new Interval(lowerBound, upperBound);
    108125
    109126      // update if there was a change
    110       if (lowerBound != Content.GetInterval(key).LowerBound ||
    111         upperBound != Content.GetInterval(key).UpperBound)
    112         Content.SetInterval(key, new Interval(lowerBound, upperBound));
     127      if (!Content.GetInterval(key).Equals(newInterval))
     128        Content.SetInterval(key, newInterval);
    113129    }
    114130
     
    118134        dataGridView.Rows[e.RowIndex].ErrorText = "Value must be a double value.";
    119135        return;
    120       } else {
    121         var lowerBound = double.Parse(dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString());
    122         var upperBound = double.Parse(dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString());
    123         if (e.ColumnIndex == 1 && value < lowerBound || e.ColumnIndex == 0 && value > upperBound) {
    124           e.Cancel = true;
    125           dataGridView.Rows[e.RowIndex].ErrorText = "Lower bound of interval must be smaller than upper bound.";
    126         }
    127136      }
     137
     138      var lowerBound = double.Parse(dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString());
     139      var upperBound = double.Parse(dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString());
     140     
     141      if (e.ColumnIndex == 0 && value > upperBound || e.ColumnIndex == 1 && value < lowerBound) {
     142        e.Cancel = true;
     143        dataGridView.Rows[e.RowIndex].ErrorText = "Lower bound of interval must be smaller than upper bound.";
     144        return;
     145      }
     146
     147      dataGridView[e.ColumnIndex, e.RowIndex].Value = value;
    128148    }
    129149
Note: See TracChangeset for help on using the changeset viewer.