zoukankan      html  css  js  c++  java
  • DataColumn.Caption属性应用到DataGridView.HeaderText的方法

    DataColumn.Caption属性在DataTable绑定到DataGridView上时,并未像想象中那样做为HeaderText来显示。

    微软官网貌似说是个小bug,从2.0至今未修正。

    DataColumn.Caption属性应用到DataGridView.HeaderText的方法有两种,网上整理:

    for (int i = 0; i < table.Columns.Count; i++) {
                if (dataGridView1.Columns.Count >= i) {
                    dataGridView1.Columns[i].HeaderText = table.Columns[i].Caption;
                }
            }

    或:

    private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
        var dGrid = (sender as DataGrid);
        if (dGrid == nullreturn ;
        var view = dGrid.ItemsSource as DataView;
        if (view == nullreturn;
        var table = view.Table;
        e.Column.HeaderText = table.Columns[e.Column.Header as String].Caption;
    }
  • 相关阅读:
    redis操作
    MySQL架构
    MySQL查询缓存
    MySQL数据备份与还原
    Sql性能优化
    Notepad++中每一行的开头和结尾添加引号?
    分组聚合
    Python3用scan和delete命令批量清理redis数据
    VUE+django
    python转化13位时间戳
  • 原文地址:https://www.cnblogs.com/bk/p/2471542.html
Copyright © 2011-2022 走看看