Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use DataGridViewCheckBoxCell in DataGridView

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use DataGridViewCheckBoxCell in DataGridView. I hope you will get something after reading this article. Let's discuss it together.

Datagridview is the most complex control in. Net, because people require a variety of table formats, it is very difficult to write a general Datagridview (similar to datatable in JSF).

In Datagridview, users can program rows, columns, and cells. For example, a variety of controls such as drop-down lists, check boxes, edit boxes, checkboxes, and so on can be inserted into the row. Each control begins with DataGridView. For example, the radio box class is DataGridViewCheckBoxCell.

DataGridViewCheckBoxCell has some disgusting attributes that have afflicted me for a long time, which are described in more detail below.

FormattedValue attribute:

You may be used to using intuitive statements like checked=true or checked=false to get the value of checkbox, but DataGridViewCheckBoxCell does not have the checked attribute and uses the more complex FormattedValue.

EditedFormattedValue attribute:

The status of the current checkbox, regardless of whether it is already a "confirmed value". As far as we can remember, checkbox has only true or false. What do you mean by "definite value"? The exact value means that the current value of checkbox is returned regardless of whether the user has left the cell (that is, to confirm the final state of the cell). At first glance, I was even more confused. Give an example to explain:

(1) checkbox is not selected at the beginning, and the user clicks it, so the checkbox will be checked.

At this point, EditedFormattedValue=true, but FormattedValue=false, this is because the user does not have the value of "confirm", and the checkbox is still in the editing state.

(2) checkbox is selected at the beginning, and the user clicks it, so the checkbox is unchecked, and then the user clicks on other cells.

At this point, EditedFormattedValue=false, but FormattedValue=false, this is because the user leaving the cell means that the user has "confirmed" the value, the checkbox is no longer in the edited state, its EditedFormattedValue==FormattedValue

At this point, EditedFormattedValue=false, but FormattedValue=false, this is because the user leaving the cell means that the user has "confirmed" the value, the checkbox is no longer in the edited state, its EditedFormattedValue==FormattedValue

The copy code is as follows:

For (int I = 0; I < dataGridView1.Rows.Count; iTunes +)

{

DataGridViewCheckBoxCell chkBoxCell = (DataGridViewCheckBoxCell) dataGridView1.Rows [I] .Cells [column _ Id.Index]

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

{

}

}

After reading this article, I believe you have a certain understanding of "how to use DataGridViewCheckBoxCell in DataGridView". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report