zoukankan      html  css  js  c++  java
  • DataGridView常用操作

    1、自动适应列宽
    DataGridView.AutoSizeColumns(DataGridViewAutoSizeColumnCriteria.HeaderAndDisplayedRows);
    DataGridView.AutoSizeColumn(DataGridViewAutoSizeColumnCriteria.HeaderOnly, 2, false);
    DataGridView.AutoSizeRow(DataGridViewAutoSizeRowCriteria.Columns, 2, false);
    DataGridView.AutoSizeRows(DataGridViewAutoSizeRowCriteria.HeaderAndColumns, 0, dataGridView1.Rows.Count, false);

    2、改变表格线条风格
    this.dataGridView1.GridColor = Color.BlueViolet;
    this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
    this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
    this.dataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
    this.dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;

    3、动态改变列是否显示,和动态改变列的显示顺序
    customersDataGridView.Columns["CustomerID"].Visible = false;
    customersDataGridView.Columns["ContactName"].DisplayIndex = 0;
    customersDataGridView.Columns["ContactTitle"].DisplayIndex = 1;
    customersDataGridView.Columns["City"].DisplayIndex = 2;
    customersDataGridView.Columns["Country"].DisplayIndex = 3;
    customersDataGridView.Columns["CompanyName"].DisplayIndex = 4;

    4、在列中显示图像
    Icon treeIcon = new Icon(this.GetType(), "tree.ico");
    DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
    iconColumn.Image = treeIcon.ToBitmap();
    iconColumn.Name = "Tree";
    iconColumn.HeaderText = "Nice tree";
    dataGridView1.Columns.Insert(2, iconColumn);

    5、格式化显示内容
    this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format = "c";
    this.dataGridView1.Columns["ShipDate"].DefaultCellStyle.Format = "d";
    this.dataGridView1.DefaultCellStyle.NullValue = "no entry";
    this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewWrapMode.Wrap;
    this.dataGridView1.Columns["CustomerName"].DefaultCellStyle.Alignment =DataGridViewContentAlignment.MiddleRight;

    6、更改列名
    dataGridView1.Columns[0].HeaderText = "序号";
    dataGridView1.Columns["SortID"].HeaderText = "分类ID";

  • 相关阅读:
    【bzoj1704】[Usaco2007 Mar]Face The Right Way 自动转身机 贪心
    【poj2104】K-th Number 主席树
    【bzoj3772】精神污染 STL+LCA+主席树
    【bzoj3932】[CQOI2015]任务查询系统 离散化+主席树
    【bzoj3545/bzoj3551】[ONTAK2010]Peaks/加强版 Kruskal+树上倍增+Dfs序+主席树
    【bzoj3524】[Poi2014]Couriers 主席树
    【bzoj2223】[Coci 2009]PATULJCI 主席树
    【bzoj2588】Spoj 10628. Count on a tree 离散化+主席树
    【bzoj1901】Zju2112 Dynamic Rankings 离散化+主席树+树状数组
    【bzoj1552】[Cerc2007]robotic sort Splay
  • 原文地址:https://www.cnblogs.com/wintalen/p/1904536.html
Copyright © 2011-2022 走看看