本文整理匯總了C#中System.Windows.Forms.DataGridViewCell.ErrorText屬性的典型用法代碼示例。如果您正苦於以下問題:C# DataGridViewCell.ErrorText屬性的具體用法?C# DataGridViewCell.ErrorText怎麽用?C# DataGridViewCell.ErrorText使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Windows.Forms.DataGridViewCell
的用法示例。
在下文中一共展示了DataGridViewCell.ErrorText屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: dataGridView1_CellValidating
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
DataGridViewColumn column = dataGridView1.Columns[e.ColumnIndex];
if (column.Name == "Track")
{
CheckTrack(e);
}
else if (column.Name == "Release Date")
{
CheckDate(e);
}
}
private static void CheckTrack(DataGridViewCellValidatingEventArgs newValue)
{
Int32 ignored = new Int32();
if (String.IsNullOrEmpty(newValue.FormattedValue.ToString()))
{
NotifyUserAndForceRedo("Please enter a track", newValue);
}
else if (!Int32.TryParse(newValue.FormattedValue.ToString(), out ignored))
{
NotifyUserAndForceRedo("A Track must be a number", newValue);
}
else if (Int32.Parse(newValue.FormattedValue.ToString()) < 1)
{
NotifyUserAndForceRedo("Not a valid track", newValue);
}
}
private static void NotifyUserAndForceRedo(string errorMessage, DataGridViewCellValidatingEventArgs newValue)
{
MessageBox.Show(errorMessage);
newValue.Cancel = true;
}
private void CheckDate(DataGridViewCellValidatingEventArgs newValue)
{
try
{
DateTime.Parse(newValue.FormattedValue.ToString()).ToLongDateString();
AnnotateCell(String.Empty, newValue);
}
catch (FormatException)
{
AnnotateCell("You did not enter a valid date.", newValue);
}
}
private void AnnotateCell(string errorMessage, DataGridViewCellValidatingEventArgs editEvent)
{
DataGridViewCell cell = dataGridView1.Rows[editEvent.RowIndex].Cells[editEvent.ColumnIndex];
cell.ErrorText = errorMessage;
}