I have about 10 grids that use the same error handling code below. Currenly this code is behind all of the grids. Is there a better place to have this code, maybe in a class, and then reference it that way? How would I do this? Kinda new to C#. P.S. I am using winforms if that makes a difference.
Code:
private void ultraGridPop_Error(object sender, Infragistics.Win.UltraWinGrid.ErrorEventArgs e)
{
// If there is an error while cutting, copying, or pasting, this
// event will fire and e.ErrorType will be MultiCellOperation.
if (e.ErrorType == ErrorType.MultiCellOperation)
{
// Cancel the default error message
e.Cancel = true;
// e.MultiCellOperationErrorInfo returns the error information.
// Build a custom error message for the user.
System.Text.StringBuilder SB = new System.Text.StringBuilder();
SB.AppendFormat("An error has occurred during the {0} operation", e.MultiCellOperationErrorInfo.Operation.ToString());
SB.Append(Environment.NewLine);
SB.Append("The error was as follows:");
SB.Append(Environment.NewLine);
SB.Append(Environment.NewLine);
SB.AppendFormat("\"{0}\"", e.ErrorText);
// Get the cell on which the error occurred
UltraGridCell errorCell = e.MultiCellOperationErrorInfo.ErrorCell;
// The ErrorCell will be null if the error was an error in the whole
// operation as oppossed to an error no a single cell.
if (errorCell != null)
{
int rowIndex = errorCell.Row.Index;
string columnCaption = errorCell.Column.Header.Caption;
SB.Append(Environment.NewLine);
SB.AppendFormat("The error occurred on Row {0} in Column {1}", rowIndex, columnCaption);
}
MessageBox.Show(this, SB.ToString());
}
}
#endregion