Okay, I am pulling my hair out and would like some help with this code. I took some code from this site to do cell validation. I don't have the current spreadsheet control and work will not pay for an upgrade, so I am trying to make due. Here is the code that does the validation I got to work (from another post):
private void ValidateCellValue(ICellValue cellValue) { bool isValid = false; string stringValue = cellValue.GetResultValueAsString(CellValueFormat.GeneralFormat); int intValue; if (int.TryParse(stringValue, out intValue)) { if (intValue >= MinIntValue && intValue <= MaxIntValue) { isValid = true; } } if (!isValid) { MessageBox.Show("Not valid!"); Workbook workbook = new Workbook(); CellIndex activeCellIndex = this.worksheetEditor.Selection.ActiveCellIndex; // Be carefull: SetValue() raises the CellPropertyChanged event. this.worksheetEditor.Worksheet.Cells[activeCellIndex].SetValue(stringValue); this.worksheetEditor.Worksheet.Cells[activeCellIndex].SetIsBold(true); GradientFill greenGradientFill = new GradientFill(GradientType.FromCenter, Color.FromRgb(255, 255, 255), Color.FromRgb(252, 231, 0)); this.worksheetEditor.Worksheet.Cells[activeCellIndex].SetFill(greenGradientFill); this.worksheetEditor.Focus(); } }As you can see, I can put a gradient fill behind the cell if the value is invalid. However, when I showed this to the users, they indicated it was to distracting and they just want the outline of the cell to be colored. So I found this code on the this site and have been trying to implement it:
private void InitializeRectangle(Rectangle rectangle, CellLayoutBox cellBox) { //rectangle.Fill = new SolidColorBrush(Colors.Red); rectangle.Stroke = new SolidColorBrush(Colors.Red); rectangle.StrokeThickness = 1; rectangle.Width = cellBox.Width; rectangle.Height = cellBox.Height; Canvas.SetLeft(rectangle, cellBox.Left); Canvas.SetRight(rectangle, cellBox.Top); }I have tried to pull this code in and replace the current gradient fill but keep running into problems. I would prefer to pass the cell to the InitializeRectangle method and have it paint the border red. Right now the method takes in a rectangle which isn't a problem, it is passing in the cellBox, how do I get the cell box in the validation method when the value is not valid?
Any help at all on this would be much appreciated.