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按钮效果。

  • 相关阅读:
    [转]ASP.NET生成HTML初级解决方案
    HTTPContentTypes 大全
    CSS美化 input type=”file” 兼容所有浏览器
    页面前端的水有多深?再议页面开发(转)
    jQuery对select、checkbox、radio操作小结
    jQuery 跟随浏览器窗口的回到顶部按钮gototop(转)
    下载apachetomcat9.0.17windowsx64及安装以及用途
    J2SE基本安装和java的环境变量
    java简单的运算符和表达式
    关于类的成员,public,private修饰符
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2104033.html
Copyright © 2011-2022 走看看