Freigeben über


DataGrid.HeadersVisibility Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value that indicates the visibility of row and column headers.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)

Syntax

'Declaration
Public Property HeadersVisibility As DataGridHeadersVisibility
public DataGridHeadersVisibility HeadersVisibility { get; set; }
<sdk:DataGrid HeadersVisibility="dataGridGridHeadersVisibilityValue"/>

XAML Values

Property Value

Type: System.Windows.Controls.DataGridHeadersVisibility
One of the enumeration values that indicates the visibility of row and column headers. The default is Column.

Remarks

Dependency property identifier field: HeadersVisibilityProperty

Examples

The following code example demonstrates how to set the HeadersVisibility property in code. This example is part of a larger example available in the Walkthrough: Customizing the DataGrid Control Using Properties topic.

Private Sub cbHeaders_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim cb As ComboBox = sender
    Dim cbi As ComboBoxItem = cb.SelectedItem
    If Me.dataGrid1 IsNot Nothing Then
        If cbi.Content.ToString() = "All" Then
            Me.dataGrid1.HeadersVisibility = DataGridHeadersVisibility.All
        ElseIf cbi.Content.ToString() = "Column (Default)" Then
            Me.dataGrid1.HeadersVisibility = DataGridHeadersVisibility.Column
        ElseIf cbi.Content.ToString() = "Row" Then
            Me.dataGrid1.HeadersVisibility = DataGridHeadersVisibility.Row
        Else
            Me.dataGrid1.HeadersVisibility = DataGridHeadersVisibility.None
        End If
    End If
End Sub
private void cbHeaders_SelectionChanged(object sender, RoutedEventArgs e)
{
    ComboBoxItem cbi = ((ComboBox)sender).SelectedItem as ComboBoxItem;
    if (this.dataGrid1 != null)
    {
        if (cbi.Content.ToString() == "All")
            this.dataGrid1.HeadersVisibility = DataGridHeadersVisibility.All;
        else if (cbi.Content.ToString() == "Column (Default)")
            this.dataGrid1.HeadersVisibility = DataGridHeadersVisibility.Column;
        else if (cbi.Content.ToString() == "Row")
            this.dataGrid1.HeadersVisibility = DataGridHeadersVisibility.Row;
        else
            this.dataGrid1.HeadersVisibility = DataGridHeadersVisibility.None;
    }

}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.