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

  • 相关阅读:
    对话框中设置静态文本框字体及颜色
    UVA 10250 The Other Two Trees(几何)
    UVA 113 Power of Cryptography(数学)
    VC++设置半透明界面
    UVA 10474 Where is the Marble?
    UVA 123 Searching Quickly(分离单词)
    为对话框在标题栏和任务栏关联图标
    UVA 152 Tree's a Crowd
    UVA 156 Ananagrams
    UVA 299 Train Swapping(冒泡排序)
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2104033.html
Copyright © 2011-2022 走看看