次の方法で共有


DataGrid.BackgroundColorChanged イベント

BackgroundColor が変更された場合に発生します。

Public Event BackgroundColorChanged As EventHandler
[C#]
public event EventHandler BackgroundColorChanged;
[C++]
public: __event EventHandler* BackgroundColorChanged;

[JScript] JScript では、このクラスで定義されているイベントを処理できます。ただし、独自に定義することはできません。

イベント データ

イベント ハンドラが EventArgs 型の引数を受け取りました。

解説

イベント処理の詳細については、「 イベントの利用 」を参照してください。

使用例

[Visual Basic, C#, C++] BackgroundColor プロパティ値を黄色から赤に変更し、 BackgroundColorChanged イベントを発生させる例を次に示します。

 
' Create an instance of the 'BackgroundColorChanged' EventHandler.
Private Sub CallBackgroundColorChanged()
   AddHandler myDataGrid.BackgroundColorChanged, AddressOf Grid_ColChange
End Sub 'CallBackgroundColorChanged


' Set the 'BackgroundColor' property on click of button.
Protected Sub myButton_Click(sender As Object, e As EventArgs)
   If op_Equality(myDataGrid.BackgroundColor ,Color.Yellow ) Then
      myDataGrid.BackgroundColor = Color.Red
   Else
      myDataGrid.BackgroundColor = Color.Yellow
   End If
End Sub 'myButton_Click


' Raise the event when 'Background' color of DataGrid changes.
Protected Sub Grid_ColChange(sender As Object, e As EventArgs)
   ' String variable used to show message.
   Dim myString As String = "BackgroundColorChanged event raised, changed to "
   ' Get the background color of DataGrid.
   Dim myColor As Color = myDataGrid.BackgroundColor
   myString += myColor.ToString()
   ' Show information about background color setting.
   MessageBox.Show(myString, "Background color information")
End Sub 'Grid_ColChange

[C#] 
// Create an instance of the 'BackgroundColorChanged' EventHandler.
private void CallBackgroundColorChanged()
{
   myDataGrid.BackgroundColorChanged += new EventHandler(Grid_ColChange);
}

// Set the 'BackgroundColor' property on click of button.
protected void myButton_Click(object sender, EventArgs e)
{
   if (myDataGrid.BackgroundColor == Color.Yellow)
   {
      myDataGrid.BackgroundColor = Color.Red;
   }
   else
   {
      myDataGrid.BackgroundColor = Color.Yellow;
   }
}

// Raise the event when 'Background' color of DataGrid changes.
protected void Grid_ColChange(object sender, EventArgs e)
{
   // String variable used to show message.
   string myString = "BackgroundColorChanged event raised, changed to ";
   // Get the background color of DataGrid.
   Color myColor = myDataGrid.BackgroundColor;
   myString += myColor.ToString();
   // Show information about background color setting.
   MessageBox.Show(myString, "Background color information");
}

[C++] 
// Create an instance of the 'BackgroundColorChanged' EventHandler.
private:
void CallBackgroundColorChanged()
{
   myDataGrid->BackgroundColorChanged += new EventHandler(this, &MyDataGrid::Grid_ColChange);
}

// Set the 'BackgroundColor' property on click of button.
protected:
void myButton_Click(Object* /*sender*/, EventArgs* /*e*/)
{
   if (myDataGrid->BackgroundColor == Color::Yellow)
   {
      myDataGrid->BackgroundColor = Color::Red;
   }
   else
   {
      myDataGrid->BackgroundColor = Color::Yellow;
   }
}

// Raise the event when 'Background' color of DataGrid changes.
void Grid_ColChange(Object* /*sender*/, EventArgs* /*e*/)
{
   // String variable used to show message.
   String* myString = S"BackgroundColorChanged event raised, changed to ";
   // Get the background color of DataGrid.
   Color myColor = myDataGrid->BackgroundColor;
   myString = String::Concat( myString, __box(myColor));
   // Show information about background color setting.
   MessageBox::Show(myString, S"Background color information");
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

DataGrid クラス | DataGrid メンバ | System.Windows.Forms 名前空間