- Timestamp:
- 05/28/20 09:35:39 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/IntervalCollectionView.cs
r17564 r17565 22 22 23 23 using System.Windows.Forms; 24 using HeuristicLab.Common; 24 25 using HeuristicLab.MainForm; 25 26 using HeuristicLab.MainForm.WindowsForms; … … 77 78 dataGridView.Rows.AddRange(rows); 78 79 79 intj = 0;80 var j = 0; 80 81 foreach (var variableInterval in Content.GetVariableIntervals()) { 81 82 dataGridView.Rows[j].HeaderCell.Value = variableInterval.Item1; … … 100 101 101 102 private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { 102 var key = dataGridView.Rows[e.RowIndex].HeaderCell.Value.ToString();103 104 103 if (e.ColumnIndex < 0 || e.RowIndex < 0) return; 105 104 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); 108 125 109 126 // 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); 113 129 } 114 130 … … 118 134 dataGridView.Rows[e.RowIndex].ErrorText = "Value must be a double value."; 119 135 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 }127 136 } 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; 128 148 } 129 149
Note: See TracChangeset
for help on using the changeset viewer.