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

  • 相关阅读:
    针对小程序for循环绑定数据,实现toggle切换效果(交流QQ群:604788754)
    小程序中bindtap绑定函数,函数参数event对数据的处理
    小程序中data数据的处理方法总结(小程序交流群:604788754)
    Power OFF and ON USB device in linux (ubuntu)
    linux控制USB的绑定/解绑
    卡内操作系统COS
    Linux内核:sk_buff解析
    skb_store_bits() 和 skb_copy_bits()
    skb详细解析【转】
    TCP:WireShark分析,序列号Seq和确认号Ack
  • 原文地址:https://www.cnblogs.com/swarb/p/9924325.html
Copyright © 2011-2022 走看看