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.ColumnHeadersVisible Property

Gets or sets a value indicating whether column headers are visible.

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

public bool ColumnHeadersVisible { get; set; }
/** @property */
public boolean get_ColumnHeadersVisible ()

/** @property */
public void set_ColumnHeadersVisible (boolean value)

public function get ColumnHeadersVisible () : boolean

public function set ColumnHeadersVisible (value : boolean)

Not applicable.

Property Value

true if column headers are visible; otherwise, false. The default is true.

To set header caption text, use the HeaderText property of the DataGridColumnStyle class.

The following code example demonstrates the use of this member.


 private void DataGridTableStyle_Sample_Load(object sender,
                                           EventArgs e)
 {
    myDataGridTableStyle1 = new DataGridTableStyle();
    myHeaderLabel.Text = "Header Status :" 
       + myDataGridTableStyle1.ColumnHeadersVisible.ToString();
    if(myDataGridTableStyle1.ColumnHeadersVisible == true)
    {
       btnheader.Text = "Remove Header";
    }
    else
    {
       btnheader.Text = "Add Header";
    }
    AddCustomDataTableStyle();
 } 
 private void AddCustomDataTableStyle()
 {           
    myDataGridTableStyle1.ColumnHeadersVisibleChanged 
       += new System.EventHandler(ColumnHeadersVisibleChanged_Handler);

    // Set ColumnheaderVisible property.         
    myDataGridTableStyle1.MappingName = "Customers";

    // Add a GridColumnStyle and set its MappingName 
    DataGridColumnStyle myBoolCol = new DataGridBoolColumn();
    myBoolCol.MappingName = "Current";
    myBoolCol.HeaderText = "IsCurrent Customer";
    myBoolCol.Width = 150;         
    myDataGridTableStyle1.GridColumnStyles.Add(myBoolCol);
 
    // Add a second column style.
    DataGridColumnStyle myTextCol = new DataGridTextBoxColumn();
    myTextCol.MappingName = "custName";
    myTextCol.HeaderText = "Customer Name";
    myTextCol.Width = 250;
    myDataGridTableStyle1.GridColumnStyles.Add(myTextCol);

    // Create new ColumnStyle objects
    DataGridColumnStyle cOrderDate = new DataGridTextBoxColumn();
    cOrderDate.MappingName = "OrderDate";
    cOrderDate.HeaderText = "Order Date";
    cOrderDate.Width = 100;

    // PropertyDescriptor to create a formatted column.
    PropertyDescriptorCollection myPropertyDescriptorCollection = this.BindingContext
       [myDataSet, "Customers.custToOrders"].GetItemProperties();
 
    // Create a formatted column using a PropertyDescriptor.         
    DataGridColumnStyle csOrderAmount = 
       new DataGridTextBoxColumn(myPropertyDescriptorCollection["OrderAmount"], "c", true);
    csOrderAmount.MappingName = "OrderAmount";
    csOrderAmount.HeaderText = "Total";
    csOrderAmount.Width = 100;

    // Add the DataGridTableStyle instances to GridTableStylesCollection.
    myDataGrid.TableStyles.Add(myDataGridTableStyle1);              
 }          
 private void ColumnHeadersVisibleChanged_Handler(object sender,
                                                       EventArgs e)
 {         
    myHeaderLabel.Text = "Header Status :" 
       + myDataGridTableStyle1.ColumnHeadersVisible.ToString();
 }      
 private void btnheader_Click(object sender, EventArgs e)
 {
    if(myDataGridTableStyle1.ColumnHeadersVisible == true)
    {            
       myDataGridTableStyle1.ColumnHeadersVisible = false;
       btnheader.Text = "Add Header";
    }
    else
    {
       myDataGridTableStyle1.ColumnHeadersVisible = true;
       btnheader.Text = "Remove Header";
    }         
}     

private void DataGridTableStyleSampleLoad(Object sender, EventArgs e)
{
    myDataGridTableStyle1 = new DataGridTableStyle();
    myHeaderLabel.set_Text("Header Status :" 
        + System.Convert.ToString(myDataGridTableStyle1.
        get_ColumnHeadersVisible()));
    if (myDataGridTableStyle1.get_ColumnHeadersVisible() == true) {
        btnheader.set_Text("Remove Header");
    }
    else {
        btnheader.set_Text("Add Header");
    }

    AddCustomDataTableStyle();
} //DataGridTableStyleSampleLoad

private void AddCustomDataTableStyle()
{
    myDataGridTableStyle1.add_ColumnHeadersVisibleChanged(
        new System.EventHandler(ColumnHeadersVisibleChanged_Handler));

    // Set ColumnheaderVisible property.         
    myDataGridTableStyle1.set_MappingName("Customers");

    // Add a GridColumnStyle and set its MappingName 
    DataGridColumnStyle myBoolCol = new DataGridBoolColumn();

    myBoolCol.set_MappingName("Current");
    myBoolCol.set_HeaderText("IsCurrent Customer");
    myBoolCol.set_Width(150);
    myDataGridTableStyle1.get_GridColumnStyles().Add(myBoolCol);

    // Add a second column style.
    DataGridColumnStyle myTextCol = new DataGridTextBoxColumn();

    myTextCol.set_MappingName("custName");
    myTextCol.set_HeaderText("Customer Name");
    myTextCol.set_Width(250);
    myDataGridTableStyle1.get_GridColumnStyles().Add(myTextCol);

    // Create new ColumnStyle objects
    DataGridColumnStyle cOrderDate = new DataGridTextBoxColumn();

    cOrderDate.set_MappingName("OrderDate");
    cOrderDate.set_HeaderText("Order Date");
    cOrderDate.set_Width(100);

    // PropertyDescriptor to create a formatted column.
    PropertyDescriptorCollection myPropertyDescriptorCollection = 
        this.get_BindingContext().get_Item(myDataSet, 
        "Customers.custToOrders").GetItemProperties();

    // Create a formatted column using a PropertyDescriptor.         
    DataGridColumnStyle csOrderAmount = 
        new DataGridTextBoxColumn(myPropertyDescriptorCollection.
        get_Item("OrderAmount"), "c", true);

    csOrderAmount.set_MappingName("OrderAmount");
    csOrderAmount.set_HeaderText("Total");
    csOrderAmount.set_Width(100);

    // Add the DataGridTableStyle instances to GridTableStylesCollection.
    myDataGrid.get_TableStyles().Add(myDataGridTableStyle1);
} //AddCustomDataTableStyle

private void ColumnHeadersVisibleChanged_Handler(Object sender, 
    EventArgs e)
{
    myHeaderLabel.set_Text("Header Status :" 
        + ((System.Boolean)myDataGridTableStyle1.
        get_ColumnHeadersVisible()).ToString());
} //ColumnHeadersVisibleChanged_Handler

private void btnheader_Click(Object sender, EventArgs e)
{
    if (myDataGridTableStyle1.get_ColumnHeadersVisible() == true) {
        myDataGridTableStyle1.set_ColumnHeadersVisible(false);
        btnheader.set_Text("Add Header");
    }
    else {
        myDataGridTableStyle1.set_ColumnHeadersVisible(true);
        btnheader.set_Text("Remove Header");
    }
} //btnheader_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: