zoukankan      html  css  js  c++  java
  • DataGridView

    一.基本知识

    (一).动态添加新行的3个方法

    方法一:

    1 int index=this.dataGridView1.Rows.Add();//返回添加新行的索引号,即新行的行号
    2 this.dataGridView1.Rows[index].Cells[0].Value = "1"; 
    3 this.dataGridView1.Rows[index].Cells[1].Value = "2"; 
    4 this.dataGridView1.Rows[index].Cells[2].Value = "3";

    方法二:

    DataGridViewRow row = new DataGridViewRow();//创建DataGridView的行对象
    DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();//单元格的内容是个 TextBox
    textboxcell.Value = "aaa";
    row.Cells.Add(textboxcell);
    DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell();//单元格的内容是下拉列表框
    row.Cells.Add(comboxcell);
    dataGridView1.Rows.Add(row);

    方法三:

    dataGridView1.Rows.Add(1, 2, 3);

     

    二.注意点

    1.设置dataGridView1.RowTemplate.Height,不能立马更新行高,后来采用的折中方法是遍历每行,改变每行的行高。

    2.当初始化dataGridView1.Width为0,设定每列的列宽,ColumnHeadersHeightSizeMode为DisableResizing,想使dataGridView1.Width=所有列宽之和,但实际dataGridView1.Width改不了(赋值第一列列宽的时候,就变成了一个比所有列宽之和大的值),后来采用的折中方法是所有列宽之和设为dataGridView1的容器的宽度。

     

    参考资料:

    C# DataGridView添加新行的2个方法_C#教程_脚本之家
    http://www.jb51.net/article/34469.htm

    DataGridView实现多维表头 - CSDN博客
    http://blog.csdn.net/fengxing11/article/details/52807502

    [转载]DataGridView二维表头与合并单元格_乔杨_新浪博客
    http://blog.sina.com.cn/s/blog_63160fa801014ity.html

     

  • 相关阅读:
    wppay免登录付费查看隐藏内容/付费资源下载
    个人网站html5雪花飘落代码JS特效下载
    HTML5 audio 如何实现播放多个MP3音频
    网站html代码解析
    vue-webpack模板升级到webpack4
    npm安装cnpm
    单个div充满屏幕的CSS方法
    vue监听滚动事件-元素固定位置显示
    HTML5中判断横屏竖屏
    The META for Mobile terminal
  • 原文地址:https://www.cnblogs.com/-lee-/p/8309368.html
Copyright © 2011-2022 走看看