zoukankan      html  css  js  c++  java
  • DataGridView

    http://blog.csdn.net/testcs_dn/article/details/9101017

    Datagridview是.net中最复杂的控件,由于人们对表格的格式要求多种多样,所以编写一个通用的Datagridview(类似JSF中的datatable)非常困难的。


    Datagridview中,用户可以对行、列、单元格进行编程。如行中可以插入下拉列表、复选框、编辑框、单选框等多种控件。每种控件都以DataGridView开头。如:单选框类为DataGridViewCheckBoxCell。

    DataGridViewCheckBoxCell有一些恶心的属性折磨了我很久,下加以详细说明。

    FormattedValue属性:

    可能大家已经习惯了用checked=true或者checked=false这样直观的语句来取得checkbox的值,但DataGridViewCheckBoxCell没有checked属性,而使用了更复杂的FormattedValue。

    EditedFormattedValue属性:

    当前checkbox的状态,不管它是不是已经是一个“确认值”。在我们在印象里,checkbox只有true或false。什么叫“确认值”呢?确认值是指:不管用户是不是已经离开该单元格(即确认该单元格最终的状态),都返回checkbox目前的值。乍一听,更糊涂了。举个例子加以解释:

    (1) 初始时checkbox未选中,用户点了一下,于是checkbox会呈现勾选状态
    这时,EditedFormattedValue=true,但FormattedValue=false,这是因为,用户没有“确认”这个值,这个checkbox仍然处于编辑状态;

    (2) 初始时checkbox选中,用户点了一下,于是checkbox会呈现未勾选状态,然后用户点击其它单元格

    这时,EditedFormattedValue=false,但FormattedValue=false,这是因为,用户离开这个单元格意味着用户已经“确认”这个值,这个checkbox不再处于编辑状态,它的EditedFormattedValue==FormattedValue

    这时,EditedFormattedValue=false,但FormattedValue=false,这是因为,用户离开这个单元格意味着用户已经“确认”这个值,这个checkbox不再处于编辑状态,它的EditedFormattedValue==FormattedValue

    [csharp] view plain copy
     
      1. for (int i = 0; i < dataGridView1.Rows.Count; i++)  
      2.             {  
      3.                 DataGridViewCheckBoxCell chkBoxCell = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[Column_Id.Index];  
      4.   
      5.                 if (chkBoxCell != null && ((bool)chkBoxCell.EditingCellFormattedValue == true || (bool)chkBoxCell.FormattedValue == true))  
      6.                 {  
      7.   
      8.                 }  
      9.             }  
  • 相关阅读:
    PAT Advanced 1067 Sort with Swap(0, i) (25分)
    PAT Advanced 1048 Find Coins (25分)
    PAT Advanced 1060 Are They Equal (25分)
    PAT Advanced 1088 Rational Arithmetic (20分)
    PAT Advanced 1032 Sharing (25分)
    Linux的at命令
    Sublime Text3使用指南
    IntelliJ IDEA创建第一个Groovy工程
    Sublime Text3 安装ftp插件
    Sublime Text3配置Groovy运行环境
  • 原文地址:https://www.cnblogs.com/luckyraye/p/7992534.html
Copyright © 2011-2022 走看看