zoukankan      html  css  js  c++  java
  • dataGridView的使用经验

    1、dataGridView是dataGrid的替代品,包含了dataGrid的全部功能。

    2、为dataGridView赋值,一般将其数据设置为一个DataTabel。例子如下:

    DataTable dt = new DataTable(); 
    for (int i = 0; i < 10; i++) 
    { 
        dt.Columns.Add(i.ToString()); //插入列 
    }
    
    for (int i= 0; i< 5; i++) //插入行 
    { 
        dt.Rows.Add("列1",“列2”。。。) 
    }
    
    dataGridView1.DataSource = dt;

    3、设置行头和列标题不可见

    dataGridView1.RowHeadersVisible = false; 
    dataGridView1.ColumnHeadersVisible = false;


    4、遍历DataGridView的单元格:

    //设置当前题号选择框 
    foreach (DataGridViewRow row in dataGridView1.Rows) 
    { 
        foreach (DataGridViewCell cell in row.Cells) 
       { 
           if (cell.Value.ToString().Trim() == num.ToString()) 
          { 
            dataGridView1.CurrentCell = cell; 
            return ; 
          } 
       } 
    }

    5、判断dataGridView的某个单元格或currentCell是否为空,直接用==来判断即可。如:

    if (dataGridView1.CurrentCell == null || dataGridView1.CurrentCell.Value.ToString().Trim() == "") 
    return;  


    6、当当前单元格发生变化时触发的事件是:CurrentCellChanged() 当鼠标点击某单元格后,触发的事件是:CellMouseClick()

    7、设置单元格颜色:

    dataGridView1.CurrentCell.Style.BackColor = Color.PaleGoldenrod;

     8、单元格的取值(将两个单元的值对调)

    object cellTemp = dataGridView1[0, i].Value;
    dataGridView1[0, i].Value = dataGridView1[0, i + 1].Value;
    dataGridView1[0, i + 1].Value = cellTemp;
    

      

  • 相关阅读:
    Python web开发——自定义userprofile(用户描述)
    Python web 开发(1)——新建项目
    小白使用pycharm+ 安装Django
    创建独立的Python开发环境virtualenvwrapper
    创建一个独立的Python 开发环境 virtualenv
    简单的爬虫demo
    Python 输入和输出
    响应式网页设计
    WEB字体,多列布局和伸缩盒
    CSS变形
  • 原文地址:https://www.cnblogs.com/huangfr/p/3185818.html
Copyright © 2011-2022 走看看