Use of DataGridView-DataGridViewCheckBoxCell

Source: Internet
Author: User

Datagridview is the most complex control in. net. It is very difficult to compile a universal Datagridview (similar to the datatable in JSF) because of various table formats.

 

In the Datagridview, you can program rows, columns, and cells. For example, you can insert a drop-down list, check box, edit box, single-dataset, and other controls into a row. Each control starts with a dview. For example, the singleton class is DataGridViewCheckBoxCell.

DataGridViewCheckBoxCell has some disgusting attributes that have plagued me for a long time. I will explain them in detail below.

FormattedValue attributes:

You may have become accustomed to using an intuitive statement such as checked = true or checked = false to obtain the checkbox value. However, the DataGridViewCheckBoxCell does not have the checked attribute, but uses a more complex FormattedValue.

EditedFormattedValue attributes:

The status of the current checkbox, whether it is a "validation value" or not ". In our impression, the checkbox is only true or false. What is "validation value? The check value indicates that the current checkbox value is returned no matter whether the user has left the cell (that is, the final status of the cell. At first glance, I was even more confused. For example:

(1) When the checkbox is not selected, the user clicks it, so the checkbox displays the check status.
At this time, EditedFormattedValue = true, but FormattedValue = false, because the user does not "Confirm" this value, the checkbox is still in the editing status;

(2) When the checkbox is selected at the beginning, the user clicks it, so the checkbox displays the unchecked status, and then the user clicks another cell.

In this case, EditedFormattedValue = false, but FormattedValue = false. This is because the user leaves the cell and the user has "Confirmed" The value. The checkbox is no longer in the editing status, and its EditedFormattedValue = FormattedValue

In this case, EditedFormattedValue = false, but FormattedValue = false. This is because the user leaves the cell and the user has "Confirmed" The value. The checkbox is no longer in the editing status, and its EditedFormattedValue = FormattedValue


[Csharp]
For (int I = 0; I <dataGridView1.Rows. Count; I ++)
{
Maid = (maid) maid [I]. Cells [Column_Id.Index];
 
If (chkBoxCell! = Null & (bool) chkBoxCell. EditingCellFormattedValue = true | (bool) chkBoxCell. FormattedValue = true ))
{
 
}
}

For (int I = 0; I <dataGridView1.Rows. Count; I ++)
{
Maid = (maid) maid [I]. Cells [Column_Id.Index];

If (chkBoxCell! = Null & (bool) chkBoxCell. EditingCellFormattedValue = true | (bool) chkBoxCell. FormattedValue = true ))
{

}
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.