本文整理汇总了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;
}