DataGridTableStyle.ForeColor Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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
Available since 1.1
Return to top
Show: