次の方法で共有


DataGridTableStyle.ForeColor プロパティ

グリッド テーブルの前景色を取得または設定します。

Public Property ForeColor As Color
[C#]
public Color ForeColor {get; set;}
[C++]
public: __property Color get_ForeColor();public: __property void set_ForeColor(Color);
[JScript]
public function get ForeColor() : Color;public function set ForeColor(Color);

プロパティ値

グリッド テーブルの前景色を表す Color

使用例

 
Private Sub Create_Table()
    ' Create a DataSet.
    myDataSet = New DataSet("myDataSet")
    ' Create DataTable.
    Dim myCustomerTable As New DataTable("Customers")
    ' Create two columns, and add to the table.
    Dim CustID As New DataColumn("CustID", GetType(Integer))
    Dim CustName As New DataColumn("CustName")
    myCustomerTable.Columns.Add(CustID)
    myCustomerTable.Columns.Add(CustName)
    Dim newRow1 As DataRow
    ' Create three customers in the Customers Table.
    Dim i As Integer
    For i = 1 To 2
        newRow1 = myCustomerTable.NewRow()
        newRow1("custID") = i
        ' Add row to the Customers table.
        myCustomerTable.Rows.Add(newRow1)
    Next i
    ' Give each customer a distinct name.
    myCustomerTable.Rows(0)("custName") = "Alpha"
    myCustomerTable.Rows(1)("custName") = "Beta"
    ' Add table to DataSet.
    myDataSet.Tables.Add(myCustomerTable)
    dataGrid1.SetDataBinding(myDataSet, "Customers")
    myTableStyle = New DataGridTableStyle()
    myTableStyle.MappingName = "Customers"
    myTableStyle.ForeColor = Color.DarkMagenta
    dataGrid1.TableStyles.Add(myTableStyle)
End Sub 'Create_Table

' Set table's forecolor.
Private Sub OnForeColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button2.Click
    dataGrid1.TableStyles.Clear()
    Select Case myComboBox.SelectedItem.ToString()
        Case "Green"
            myTableStyle.ForeColor = Color.Green
        Case "Red"
            myTableStyle.ForeColor = Color.Red
        Case "Violet"
            myTableStyle.ForeColor = Color.Violet
    End Select
    dataGrid1.TableStyles.Add(myTableStyle)
End Sub 'OnForeColor_Click

[C#] 
private void Create_Table()
{
   // Create a DataSet.
   myDataSet = new DataSet("myDataSet");
   // Create DataTable.
   DataTable myCustomerTable = new DataTable("Customers");
   // Create two columns, and add to the table.
   DataColumn CustID = new DataColumn("CustID", typeof(int));
   DataColumn CustName = new DataColumn("CustName");
   myCustomerTable.Columns.Add(CustID);
   myCustomerTable.Columns.Add(CustName);
   DataRow newRow1;
   // Create three customers in the Customers Table.
   for(int i = 1; i < 3; i++)
   {
      newRow1 = myCustomerTable.NewRow();
      newRow1["custID"] = i;
      // Add row to the Customers table.
      myCustomerTable.Rows.Add(newRow1);
   }
   // Give each customer a distinct name.
   myCustomerTable.Rows[0]["custName"] = "Alpha";
   myCustomerTable.Rows[1]["custName"] = "Beta";
   // Add table to DataSet.
   myDataSet.Tables.Add(myCustomerTable);
   dataGrid1.SetDataBinding(myDataSet,"Customers");
   myTableStyle = new DataGridTableStyle();
   myTableStyle.MappingName = "Customers";
   myTableStyle.ForeColor  = Color.DarkMagenta;
   dataGrid1.TableStyles.Add(myTableStyle);
}

// Set table's forecolor.
private void OnForeColor_Click(object sender, System.EventArgs e)
{
   dataGrid1.TableStyles.Clear();
   switch(myComboBox.SelectedItem.ToString())
   {
      case "Green":
         myTableStyle.ForeColor = Color.Green;
         break;
      case "Red":
         myTableStyle.ForeColor = Color.Red;
         break;
      case "Violet":
         myTableStyle.ForeColor = Color.Violet;
         break;
   }
   dataGrid1.TableStyles.Add(myTableStyle);
}

[C++] 
private:
    void Create_Table() {
        // Create a DataSet.
        myDataSet = new DataSet(S"myDataSet");
        // Create DataTable.
        DataTable* myCustomerTable = new DataTable(S"Customers");
        // Create two columns, and add to the table.
        DataColumn* CustID = new DataColumn(S"CustID", __typeof(int));
        DataColumn* CustName = new DataColumn(S"CustName");
        myCustomerTable->Columns->Add(CustID);
        myCustomerTable->Columns->Add(CustName);
        DataRow* newRow1;
        // Create three customers in the Customers Table.
        for (int i = 1; i < 3; i++) {
            newRow1 = myCustomerTable->NewRow();
            newRow1->Item[S"custID"] = __box(i);
            // Add row to the Customers table.
            myCustomerTable->Rows->Add(newRow1);
        }
        // Give each customer a distinct name.
        myCustomerTable->Rows->Item[0]->Item[S"custName"] = S"Alpha";
        myCustomerTable->Rows->Item[1]->Item[S"custName"] = S"Beta";
        // Add table to DataSet.
        myDataSet->Tables->Add(myCustomerTable);
        dataGrid1->SetDataBinding(myDataSet, S"Customers");
        myTableStyle = new DataGridTableStyle();
        myTableStyle->MappingName = S"Customers";
        myTableStyle->ForeColor  = Color::DarkMagenta;
        dataGrid1->TableStyles->Add(myTableStyle);
    }

    // Set table's forecolor.
    void OnForeColor_Click(Object* /*sender*/, System::EventArgs* /*e*/) {
        dataGrid1->TableStyles->Clear();

        String* str = dynamic_cast<String*>(myComboBox->SelectedItem);
        if (str->Equals(S"Green"))
            myTableStyle->ForeColor = Color::Green;
        else if (str->Equals(S"Red"))
            myTableStyle->ForeColor = Color::Red;
        else if (str->Equals(S"Violet"))
            myTableStyle->ForeColor = Color::Violet;


        dataGrid1->TableStyles->Add(myTableStyle);
    }

[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 ファミリ

参照

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