DataGridTableStyle.ForeColor Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the foreground color of the grid table.
public:
property System::Drawing::Color ForeColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
public System.Drawing.Color ForeColor { get; set; }
member this.ForeColor : System.Drawing.Color with get, set
Public Property ForeColor As Color
Property Value
A Color that represents the foreground color of the grid table.
Examples
The following code example demonstrates the use of this member.
private:
void Create_Table()
{
// Create a DataSet.
myDataSet = gcnew DataSet( "myDataSet" );
// Create DataTable.
DataTable^ myCustomerTable = gcnew DataTable( "Customers" );
// Create two columns, and add to the table.
DataColumn^ CustID = gcnew DataColumn( "CustID",int::typeid );
DataColumn^ CustName = gcnew 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 );
}
myCustomerTable->Rows[ 0 ][ "custName" ] = "Alpha";
myCustomerTable->Rows[ 1 ][ "custName" ] = "Beta";
// Add table to DataSet.
myDataSet->Tables->Add( myCustomerTable );
dataGrid1->SetDataBinding( myDataSet, "Customers" );
myTableStyle = gcnew DataGridTableStyle;
myTableStyle->MappingName = "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( "Green" ) )
myTableStyle->ForeColor = Color::Green;
else
if ( str->Equals( "Red" ) )
myTableStyle->ForeColor = Color::Red;
else
if ( str->Equals( "Violet" ) )
myTableStyle->ForeColor = Color::Violet;
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", 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 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
' 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
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기