Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataGridTableStyle.ForeColor Property

Gets or sets the foreground color of the grid table.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public Color ForeColor { get; set; }
/** @property */
public Color get_ForeColor ()

/** @property */
public void set_ForeColor (Color value)

public function get ForeColor () : Color

public function set ForeColor (value : Color)

Not applicable.

Property Value

A Color that represents the foreground color of the grid table.

The following code example demonstrates the use of this member.

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);
}

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", int.class.ToType());
    DataColumn custName = new DataColumn("CustName");

    myCustomerTable.get_Columns().Add(custID);
    myCustomerTable.get_Columns().Add(custName);

    DataRow newRow1;

    // Create three customers in the Customers Table.
    for (int i = 1; i < 3; i++) {
        newRow1 = myCustomerTable.NewRow();
        newRow1.set_Item("CustID", (Int32)i);

        // Add row to the Customers table.
        myCustomerTable.get_Rows().Add(newRow1);
    }

    // Give each customer a distinct name.
    myCustomerTable.get_Rows().get_Item(0).set_Item("custName", "Alpha");
    myCustomerTable.get_Rows().get_Item(1).set_Item("custName", "Beta");

    // Add table to DataSet.
    myDataSet.get_Tables().Add(myCustomerTable);
    dataGrid1.SetDataBinding(myDataSet, "Customers");
    myTableStyle = new DataGridTableStyle();
    myTableStyle.set_MappingName("Customers");
    myTableStyle.set_ForeColor(Color.get_DarkMagenta());
    dataGrid1.get_TableStyles().Add(myTableStyle);
} //Create_Table

// Set table's forecolor.
private void OnForeColor_Click(Object sender, System.EventArgs e)
{
    dataGrid1.get_TableStyles().Clear();
    if (myComboBox.get_SelectedItem().ToString().Equals("Green")) {
        myTableStyle.set_ForeColor(Color.get_Green());
    }
    else if (myComboBox.get_SelectedItem().ToString().Equals("Red")) {
        myTableStyle.set_ForeColor(Color.get_Red());
    }
    else if (myComboBox.get_SelectedItem().ToString().Equals("Violet")) {
        myTableStyle.set_ForeColor(Color.get_Violet());
    }
    dataGrid1.get_TableStyles().Add(myTableStyle);
} //OnForeColor_Click

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

Show:
© 2014 Microsoft