zoukankan      html  css  js  c++  java
  • wpf DataGrid的操作

    [本篇内容来自网络] 

    public DataGrid CreateDataGrid()
            {
     //自定义DataGrid
                DataGrid dataGrid = null;
                dataGrid = new DataGrid();

                dataGrid.Height = 340;
                dataGrid.Margin = new Thickness(10, 30, 0, 0);
                dataGrid.IsReadOnly = true;
                dataGrid.AutoGenerateColumns = false;
                dataGrid.CanUserResizeColumns = false;
                System.Windows.Data.Binding binding = null;
                binding = new System.Windows.Data.Binding("E_ID");
                binding.Mode = System.Windows.Data.BindingMode.OneWay;
                DataGridTextColumn dgtcE_Id = null;
                dgtcE_Id = new DataGridTextColumn();
                dgtcE_Id.Header = "编号";
                dgtcE_Id.Width = 70;
                dgtcE_Id.Visibility = Visibility.Collapsed;
                dgtcE_Id.Binding = binding;
                dataGrid.Columns.Add(dgtcE_Id);
                binding = new System.Windows.Data.Binding("E_Type");
                binding.Mode = System.Windows.Data.BindingMode.OneWay;
                DataGridTextColumn dgtcE_Type = null;
                dgtcE_Type = new DataGridTextColumn();
                dgtcE_Type.Header = "下拉框名称";
                dgtcE_Type.Width = 200;
                dgtcE_Type.Binding = binding;
                dataGrid.Columns.Add(dgtcE_Type);
                binding = new System.Windows.Data.Binding("E_TypeName");
                binding.Mode = System.Windows.Data.BindingMode.OneWay;
                DataGridTextColumn dgtcE_TypeName = null;
                dgtcE_TypeName = new DataGridTextColumn();
                dgtcE_TypeName.Header = "下拉框内容";
                dgtcE_TypeName.Width = 200;
                dgtcE_TypeName.Binding = binding;
                dataGrid.Columns.Add(dgtcE_TypeName);
                binding = new System.Windows.Data.Binding("状态");
                binding.Mode = System.Windows.Data.BindingMode.OneWay;
                DataGridTextColumn dgtcReveaState = null;
                dgtcReveaState = new DataGridTextColumn();
                dgtcReveaState.Header = "是否启用";
                dgtcReveaState.Width = 120;
                dgtcReveaState.Binding = binding;
                dataGrid.Columns.Add(dgtcReveaState);

     //DataGrid中Column的内容居中
                Style styleRight = new Style(typeof(TextBlock));
                Setter setRight = new Setter(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                styleRight.Setters.Add(setRight);
                foreach (DataGridColumn c in dataGrid.Columns)
                {
                    DataGridTextColumn tc = c as DataGridTextColumn;
                    if (tc != null)
                    {
                        tc.ElementStyle = styleRight;
                    }
                }

     //表头居中
                Style style = new Style(typeof(DataGridColumnHeader));
                setRight = new Setter(DataGridColumnHeader.HorizontalContentAlignmentProperty, HorizontalAlignment.Center);
                style.Setters.Add(setRight);
                dataGrid.ColumnHeaderStyle = style;

                return dataGrid;
            }

  • 相关阅读:
    关于FPGA设计16位乘法器的两…
    const int *pi与int&nbs…
    HTML5基础学习
    html5基础!!
    正确分析结构使用正确的HTML标签。CSS样式写一起。
    开发经验以及方法
    布局设计
    position定位
    浏览器的兼容性
    float浮动的世界
  • 原文地址:https://www.cnblogs.com/xtzhilv/p/2279631.html
Copyright © 2011-2022 走看看