当前位置: 首页>>代码示例>>C#>>正文


C# DataGridColumn.Visibility属性代码示例

本文整理汇总了C#中System.Windows.Controls.DataGridColumn.Visibility属性的典型用法代码示例。如果您正苦于以下问题:C# DataGridColumn.Visibility属性的具体用法?C# DataGridColumn.Visibility怎么用?C# DataGridColumn.Visibility使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。


在下文中一共展示了DataGridColumn.Visibility属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DG1_AutoGeneratingColumn

private void DG1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
    //Set properties on the columns during auto-generation
    switch (e.Column.Header.ToString())
    {
        case "LastName":
            e.Column.CanUserSort = false;
            e.Column.Visibility = Visibility.Visible;
            break;
        case "FirstName":
            e.Column.Visibility = Visibility.Visible;
            break;
        case "CompanyName":
            e.Column.Visibility = Visibility.Visible;
            break;
        case "EmailAddress":
            e.Column.Visibility = Visibility.Visible;
            break;
        default:
            e.Column.Visibility = Visibility.Collapsed;
            break;
    }
}

private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
    //Make each column in the collection visible
    foreach (DataGridColumn col in DG1.Columns)
    {
        col.Visibility = Visibility.Visible;
    }
}

private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
    //Get the columns collection
    ObservableCollection<DataGridColumn> columns = DG1.Columns;

    //set the visibility for each column so only 4 columns are visible
    foreach (DataGridColumn col in columns)
    {
        switch (col.Header.ToString())
        {
            case "LastName":
                col.Visibility = Visibility.Visible;
                break;
            case "FirstName":
                col.Visibility = Visibility.Visible;
                break;
            case "CompanyName":
                col.Visibility = Visibility.Visible;
                break;
            case "EmailAddress":
                col.Visibility = Visibility.Visible;
                break;
            default:
                col.Visibility = Visibility.Collapsed;
                break;
        }
    }
}
开发者ID:.NET开发者,项目名称:System.Windows.Controls,代码行数:61,代码来源:DataGridColumn.Visibility


注:本文中的System.Windows.Controls.DataGridColumn.Visibility属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。