void SetRowErrorText(GridViewRowInfo row) { if (row != null) { bool validationFailed = false; StringBuilder validationMessage = new StringBuilder(); foreach (RadListDataItem item in radComboBox1.Items) { ColumnValidationInfo validationInfo = (ColumnValidationInfo)item.Value; object value = row.Cells[validationInfo.Column.HeaderText].Value; if (Convert.IsDBNull(value)) { value = null; } if (!validationInfo.Validate(Convert.ToDecimal(value))) { validationFailed = true; validationMessage.Append(validationInfo.Column.HeaderText + " " + validationInfo.GetMessage(Convert.ToDecimal(value)) + "\n"); } if (radGridView1.IsInEditMode && radGridView1.CurrentRow == row && radGridView1.CurrentColumn == validationInfo.Column) { object editorValue = radGridView1.ActiveEditor.Value; if (Convert.IsDBNull(editorValue)) { editorValue = value; } if (!validationInfo.Validate(Convert.ToDecimal(editorValue))) { validationFailed = true; validationMessage.Append(validationInfo.Column.HeaderText + " " + validationInfo.GetMessage(Convert.ToDecimal(editorValue)) + "\n"); } } } row.ErrorText = validationFailed ? validationMessage.ToString() : string.Empty; } }
private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e) { if (radGridView1.IsInEditMode) { ColumnValidationInfo validationInfo = GetColumnValidationInfo(e.Column); if (validationInfo != null && !validationInfo.Validate(Convert.ToDecimal(e.Value))) { e.Cancel = true; e.Row.ErrorText = "Validation Error!"; } } }
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) { if (e.CellElement.RowElement is GridDataRowElement) { ColumnValidationInfo validationInfo = GetColumnValidationInfo(e.CellElement.ColumnInfo); if (validationInfo != null) { object value = ((GridDataCellElement)e.CellElement).Value; if (Convert.IsDBNull(value)) { value = null; } if (!validationInfo.Validate(Convert.ToDecimal(value))) { e.CellElement.DrawFill = true; e.CellElement.GradientStyle = GradientStyles.Linear; e.CellElement.GradientPercentage = 0.45f; e.CellElement.GradientPercentage2 = 0.53f; e.CellElement.NumberOfColors = 4; e.CellElement.BackColor = Color.FromArgb(253, 141, 142); e.CellElement.BackColor2 = Color.FromArgb(254, 86, 86); e.CellElement.BackColor3 = Color.FromArgb(254, 55, 55); e.CellElement.BackColor4 = Color.FromArgb(254, 31, 32); e.CellElement.BorderGradientStyle = GradientStyles.Solid; e.CellElement.BorderColor = Color.FromArgb(254, 31, 32); e.CellElement.ZIndex = 100; } else if (e.CellElement.BackColor == Color.FromArgb(253, 141, 142)) { e.CellElement.ResetValue(RadItem.BackColorProperty); e.CellElement.ResetValue(LightVisualElement.DrawFillProperty); e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty); e.CellElement.ResetValue(LightVisualElement.GradientPercentageProperty); e.CellElement.ResetValue(LightVisualElement.GradientPercentage2Property); e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty); e.CellElement.ResetValue(LightVisualElement.BackColor2Property); e.CellElement.ResetValue(LightVisualElement.BackColor3Property); e.CellElement.ResetValue(LightVisualElement.BackColor4Property); e.CellElement.ResetValue(LightVisualElement.BorderGradientStyleProperty); e.CellElement.ResetValue(LightVisualElement.BorderColorProperty); e.CellElement.ResetValue(RadElement.ZIndexProperty); } } } }