本文整理匯總了VB.NET中System.Windows.Forms.DataGridViewCell.ErrorText屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET DataGridViewCell.ErrorText屬性的具體用法?VB.NET DataGridViewCell.ErrorText怎麽用?VB.NET DataGridViewCell.ErrorText使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Windows.Forms.DataGridViewCell
的用法示例。
在下文中一共展示了DataGridViewCell.ErrorText屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: CheckTrack
Private Sub dataGridView1_CellValidating(ByVal sender As Object, _
ByVal e As _
DataGridViewCellValidatingEventArgs) _
Handles dataGridView1.CellValidating
Dim column As DataGridViewColumn = _
dataGridView1.Columns(e.ColumnIndex)
If column.Name = "Track" Then
CheckTrack(e)
ElseIf column.Name = "Release Date" Then
CheckDate(e)
End If
End Sub
Private Shared Sub CheckTrack(ByVal newValue As DataGridViewCellValidatingEventArgs)
If String.IsNullOrEmpty(newValue.FormattedValue.ToString()) Then
NotifyUserAndForceRedo("Please enter a track", newValue)
ElseIf Not Integer.TryParse( _
newValue.FormattedValue.ToString(), New Integer()) Then
NotifyUserAndForceRedo("A Track must be a number", newValue)
ElseIf Integer.Parse(newValue.FormattedValue.ToString()) < 1 Then
NotifyUserAndForceRedo("Not a valid track", newValue)
End If
End Sub
Private Shared Sub NotifyUserAndForceRedo(ByVal errorMessage As String, ByVal newValue As DataGridViewCellValidatingEventArgs)
MessageBox.Show(errorMessage)
newValue.Cancel = True
End Sub
Private Sub CheckDate(ByVal newValue As DataGridViewCellValidatingEventArgs)
Try
DateTime.Parse(newValue.FormattedValue.ToString()).ToLongDateString()
AnnotateCell(String.Empty, newValue)
Catch ex As FormatException
AnnotateCell("You did not enter a valid date.", newValue)
End Try
End Sub
Private Sub AnnotateCell(ByVal errorMessage As String, _
ByVal editEvent As DataGridViewCellValidatingEventArgs)
Dim cell As DataGridViewCell = _
dataGridView1.Rows(editEvent.RowIndex).Cells( _
editEvent.ColumnIndex)
cell.ErrorText = errorMessage
End Sub