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;
            }

  • 相关阅读:
    layui框架如何在停止服务用户操作任何步骤自动跳转登录页
    h5移动端和ios以及安卓客户端的接口联调
    sublime 主要使用方法
    内外边距、浮动、布局相关
    js介绍
    css的三个特性 背景透明设置
    选择器 导航制作相关
    表单综合
    自定义列表dl
    相对路径和绝对路径
  • 原文地址:https://www.cnblogs.com/xtzhilv/p/2279631.html
Copyright © 2011-2022 走看看