DataGridView.RowValidating イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridView.RowValidating イベントの意味・解説 

DataGridView.RowValidating イベント

メモ : このイベントは、.NET Framework version 2.0新しく追加されたものです。

行が検証行っているときに発生します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Event RowValidating As
 DataGridViewCellCancelEventHandler
Dim instance As DataGridView
Dim handler As DataGridViewCellCancelEventHandler

AddHandler instance.RowValidating, handler
public event DataGridViewCellCancelEventHandler RowValidating
public:
event DataGridViewCellCancelEventHandler^ RowValidating {
    void add (DataGridViewCellCancelEventHandler^ value);
    void remove (DataGridViewCellCancelEventHandler^ value);
}
/** @event */
public void add_RowValidating (DataGridViewCellCancelEventHandler
 value)

/** @event */
public void remove_RowValidating (DataGridViewCellCancelEventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

RowValidating使用して有効な追跡日およびリリース日入力されたかどうかを確認するコード例次に示します

Private Sub ValidateByRow(ByVal
 sender As Object, _
    ByVal data As DataGridViewCellCancelEventArgs)
 _
    Handles songsDataGridView.RowValidating

    Dim row As DataGridViewRow = _
        songsDataGridView.Rows(data.RowIndex)
    Dim trackCell As DataGridViewCell = _
        row.Cells(songsDataGridView.Columns("Track").Index)
    Dim dateCell As DataGridViewCell = _
        row.Cells(songsDataGridView.Columns("Release Date").Index)
    data.Cancel = Not (IsTrackGood(trackCell) _
        AndAlso IsDateGood(dateCell))
End Sub

Private Function IsTrackGood(ByRef
 cell As DataGridViewCell) As Boolean

    If cell.Value.ToString().Length = 0 Then
        cell.ErrorText = "Please enter a track"
        songsDataGridView.Rows(cell.RowIndex).ErrorText = _
            "Please enter a track"
        Return False
    ElseIf cell.Value.ToString().Equals("0")
 Then
        cell.ErrorText = "Zero is not a valid track"
        songsDataGridView.Rows(cell.RowIndex).ErrorText = _
            "Zero is not a valid track"
        Return False
    ElseIf Not Integer.TryParse(
 _
        cell.Value.ToString(), New Integer())
 Then
        cell.ErrorText = "A Track must be a number"
        songsDataGridView.Rows(cell.RowIndex).ErrorText = _
            "A Track must be a number"
        Return False
    End If
    Return True
End Function

Private Function IsDateGood(ByRef
 cell As DataGridViewCell) As Boolean

    If cell.Value Is Nothing
 Then
        cell.ErrorText = "Missing date"
        songsDataGridView.Rows(cell.RowIndex).ErrorText = _
            "Missing date"
        Return False
    Else
        Try
            DateTime.Parse(cell.Value.ToString())
        Catch ex As FormatException

            cell.ErrorText = "Invalid format"
            songsDataGridView.Rows(cell.RowIndex).ErrorText = _
                "Invalid format"

            Return False
        End Try
    End If
    Return True
End Function
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataGridView.RowValidating イベント」の関連用語

DataGridView.RowValidating イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridView.RowValidating イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS