DataGridTableStyle.HeaderBackColor プロパティ
ヘッダーの背景色を取得または設定します。
Public Property HeaderBackColor As Color
[C#]
public Color HeaderBackColor {get; set;}
[C++]
public: __property Color get_HeaderBackColor();public: __property void set_HeaderBackColor(Color);
[JScript]
public function get HeaderBackColor() : Color;public function set HeaderBackColor(Color);
プロパティ値
ヘッダーの背景色を表す Color 。
使用例
Private Sub Create_Table()
' Create DataSet.
myDataSet = New DataSet("myDataSet")
' Create DataTable.
Dim myCustomerTable As New DataTable("Customers")
' Create two columns, and add them 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)
' Add table to DataSet.
myDataSet.Tables.Add(myCustomerTable)
dataGrid1.SetDataBinding(myDataSet, "Customers")
myTableStyle = New DataGridTableStyle()
myTableStyle.MappingName = "Customers"
AddHandler myTableStyle.HeaderBackColorChanged, AddressOf HeaderBackColorChangedHandler
AddHandler myTableStyle.HeaderForeColorChanged, AddressOf HeaderForeColorChangedHandler
End Sub 'Create_Table
' Change header background color.
Private Sub OnHeaderBackColor_Click(sender As Object, e As System.EventArgs) Handles button1.Click
dataGrid1.TableStyles.Clear()
Select Case comboBox1.SelectedItem.ToString()
Case "Red"
myTableStyle.HeaderBackColor = Color.Red
Case "Yellow"
myTableStyle.HeaderBackColor = Color.Yellow
Case "Blue"
myTableStyle.HeaderBackColor = Color.Blue
End Select
myTableStyle.AlternatingBackColor = Color.LightGray
dataGrid1.TableStyles.Add(myTableStyle)
End Sub 'OnHeaderBackColor_Click
[C#]
private void Create_Table()
{
// Create DataSet.
myDataSet = new DataSet("myDataSet");
// Create DataTable.
DataTable myCustomerTable = new DataTable("Customers");
// Create two columns, and add them to the table.
DataColumn CustID = new DataColumn("CustID", typeof(int));
DataColumn CustName = new DataColumn("CustName");
myCustomerTable.Columns.Add(CustID);
myCustomerTable.Columns.Add(CustName);
// Add table to DataSet.
myDataSet.Tables.Add(myCustomerTable);
dataGrid1.SetDataBinding(myDataSet,"Customers");
myTableStyle = new DataGridTableStyle();
myTableStyle.MappingName = "Customers";
myTableStyle.HeaderBackColorChanged +=
new System.EventHandler(HeaderBackColorChangedHandler);
myTableStyle.HeaderForeColorChanged +=
new System.EventHandler(HeaderForeColorChangedHandler);
}
// Change header background color.
private void OnHeaderBackColor_Click(object sender, System.EventArgs e)
{
dataGrid1.TableStyles.Clear ();
switch(comboBox1.SelectedItem.ToString())
{
case "Red":
myTableStyle.HeaderBackColor = Color.Red;
break;
case "Yellow":
myTableStyle.HeaderBackColor = Color.Yellow ;
break;
case "Blue":
myTableStyle.HeaderBackColor = Color.Blue ;
break;
}
myTableStyle.AlternatingBackColor = Color.LightGray;
dataGrid1.TableStyles.Add(myTableStyle);
}
[C++]
private:
void Create_Table() {
// Create DataSet.
myDataSet = new DataSet(S"myDataSet");
// Create DataTable.
DataTable* myCustomerTable = new DataTable(S"Customers");
// Create two columns, and add them 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);
// Add table to DataSet.
myDataSet->Tables->Add(myCustomerTable);
dataGrid1->SetDataBinding(myDataSet, S"Customers");
myTableStyle = new DataGridTableStyle();
myTableStyle->MappingName = S"Customers";
myTableStyle->HeaderBackColorChanged +=
new System::EventHandler(this, &Form1::HeaderBackColorChangedHandler);
myTableStyle->HeaderForeColorChanged +=
new System::EventHandler(this, &Form1::HeaderForeColorChangedHandler);
}
// Change header background color.
void OnHeaderBackColor_Click(Object* /*sender*/, System::EventArgs* /*e*/) {
dataGrid1->TableStyles->Clear();
String* str = dynamic_cast<String*>(comboBox1->SelectedItem);
if (str->Equals(S"Red"))
myTableStyle->ForeColor = Color::Red;
else if (str->Equals(S"Yellow"))
myTableStyle->ForeColor = Color::Yellow;
else if (str->Equals(S"Blue"))
myTableStyle->ForeColor = Color::Blue;
myTableStyle->AlternatingBackColor = Color::LightGray;
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 名前空間 | ShouldSerializeHeaderBackColor | ResetHeaderBackColor | HeaderForeColor | ColumnHeadersVisible | HeaderFont