Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ForeColor Property

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 Value

Type: System.Drawing.Color
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);
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2015 Microsoft