DataGridViewCell.ErrorText プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridViewCell.ErrorText プロパティの意味・解説 

DataGridViewCell.ErrorText プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

セル関連付けられたエラー条件記述するテキスト取得または設定します

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

Dim instance As DataGridViewCell
Dim value As String

value = instance.ErrorText

instance.ErrorText = value
public string ErrorText { get;
 set; }
/** @property */
public String get_ErrorText ()

/** @property */
public void set_ErrorText (String value)

プロパティ
セル関連付けられたエラー条件記述するテキスト

解説解説

通常ErrorText プロパティは、DataGridView の CellValidating イベント処理する際に使用されます。セル値が特定の妥当性検査基準満たしてない場合ErrorText プロパティ設定し、DataGridViewCellValidatingEventArgs の Cancel プロパティtrue設定することでコミット操作キャンセルしますその後指定したテキストDataGridView表示されユーザーセルデータエラー修正求めダイアログ ボックス表示されます。

DataGridView の VirtualMode プロパティtrue場合、RowErrorTextNeeded イベントおよび CellErrorTextNeeded イベント使用して、行とセルエラー テキストを提供できます

別の ErrorText 文字列セル割り当てると、DataGridView コントロールの CellErrorTextChanged イベント発生します

使用例使用例

バインドDataGridViewエラー条件処理する際にこのプロパティ使用する方法次のコード例示しますAnnotateCell メソッドが、エラー メッセージ文字列ErrorText プロパティ設定します

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
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;
}
void dataGridView1_CellValidating( Object^ /*sender*/, DataGridViewCellValidatingEventArgs^
 newValue )
{
   DataGridViewColumn^ column = dataGridView1->Columns[ newValue->ColumnIndex
 ];
   if ( column->Name->Equals( "Track" ) )
   {
      CheckTrack( newValue );
   }
   else
   if ( column->Name->Equals( "Release Date" )
 )
   {
      CheckDate( newValue );
   }
}

void CheckTrack( DataGridViewCellValidatingEventArgs^ newValue
 )
{
   Int32 ignored;
   if ( newValue->FormattedValue->ToString() == String::Empty
 )
   {
      NotifyUserAndForceRedo( "Please enter a track", newValue );
   }
   else
   if (  !Int32::TryParse( newValue->FormattedValue->ToString(),
 ignored ) )
   {
      NotifyUserAndForceRedo( "A Track must be a number", newValue );
   }
   else
   if ( Int32::Parse( newValue->FormattedValue->ToString()
 ) < 1 )
   {
      NotifyUserAndForceRedo( "Not a valid track", newValue );
      editedLastColumn = true;
   }
}

void NotifyUserAndForceRedo( String^ errorMessage, DataGridViewCellValidatingEventArgs^
 newValue )
{
   MessageBox::Show( errorMessage );
   newValue->Cancel = true;
}

void CheckDate( DataGridViewCellValidatingEventArgs^ newValue
 )
{
   try
   {
      DateTime::Parse( newValue->FormattedValue->ToString() ).ToLongDateString();
      AnnotateCell( String::Empty, newValue );
   }
   catch ( FormatException^ /*ex*/ ) 
   {
      AnnotateCell( "You did not enter a valid date.", newValue );
   }
}

void AnnotateCell( String^ errorMessage, DataGridViewCellValidatingEventArgs^
 editEvent )
{
   DataGridViewCell^ cell = dataGridView1->Rows[ editEvent->RowIndex ]->Cells[
 editEvent->ColumnIndex ];
   cell->ErrorText = errorMessage;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewCell クラス
DataGridViewCell メンバ
System.Windows.Forms 名前空間
DataGridView クラス
DataGridViewCellValidatingEventArgs
DataGridView.CellValidating イベント
DataGridView.VirtualMode プロパティ
DataGridView.RowErrorTextNeeded イベント
DataGridView.CellErrorTextNeeded イベント
DataGridView.CellErrorTextChanged イベント
CancelEventArgs.Cancel


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataGridViewCell.ErrorText プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataGridViewCell.ErrorText プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataGridViewCell.ErrorText プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

「DataGridViewCell.ErrorText プロパティ」の関連用語

DataGridViewCell.ErrorText プロパティのお隣キーワード
検索ランキング

   

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



DataGridViewCell.ErrorText プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS