zoukankan      html  css  js  c++  java
  • DataGridViewCell 类

    // Sets the ToolTip text for cells in the Rating column.
    void dataGridView1_CellFormatting(object sender, 
        DataGridViewCellFormattingEventArgs e)
    {
        
    if ( (e.ColumnIndex == this.dataGridView1.Columns["Rating"].Index)
            
    && e.Value != null )
        {
            DataGridViewCell cell 
    = 
                
    this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
            
    if (e.Value.Equals("*"))
            {                
                cell.ToolTipText 
    = "very bad";
            }
            
    else if (e.Value.Equals("**"))
            {
                cell.ToolTipText 
    = "bad";
            }
            
    else if (e.Value.Equals("***"))
            {
                cell.ToolTipText 
    = "good";
            }
            
    else if (e.Value.Equals("****"))
            {
                cell.ToolTipText 
    = "very good";
            }
        }
    }
                DataGridViewCell cell = dgViewer.Rows[0].Cells[0];
                DataGridViewColumn dgvc = new DataGridViewColumn(cell);
                //dgvc.DefaultCellStyle.BackColor = Color.CadetBlue;
                dgvc.ReadOnly = true;
                dgvc.HeaderText = header;
                //dgvc.Tag = type;
                dgvc.Name = name;
                int? index = null;
                index = dgViewer.Columns[dgViewer.Columns.Count - 1].Index;
                dgViewer.Columns.Insert(index.Value + 1, dgvc);

     

             添加各列: 
               DataGridViewTextBoxColumn TXTcolumn 
    = new DataGridViewTextBoxColumn(); 
               TXTcolumn.DataPropertyName 
    = "字段"
               TXTcolumn.HeaderText 
    = "名称"
               TXTcolumn.Name 
    = "名称"
               TXTcolumn.Width 
    = 60
               DataGridView1.Columns.Add(TXTcolumn); 

                依次添加所有列。 
                其他列可根据需要设置DefaultCellStyle。 
                如果要突起的效果,还可以用DataGridViewButtonColumn按钮效果。

  • 相关阅读:
    面向对象:类的基础
    Apache:dbutils 开源JDBC工具类库
    JDBCToolsV3 :DAO
    JDBCToolsV2:利用ThreadLocal保证当前线程操作同一个数据库连接对象。
    JDBC: ThreadLocal 类
    JDBCTools 第一个版本
    数据库连接池
    JDBC:处理事务
    应变片安装
    博客园 PT100 烟温隔离板资料
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2104033.html
Copyright © 2011-2022 走看看