How to Use checkbox in the datagridview in C #

Source: Internet
Author: User

View plaincopy to clipboardprint?
1. Attribute setting checkboxcolumn

Name: cb_check
Falsevalue: false
Truevalue: True
Set readonly to false in the datagridview.

2. // single-item selection settings
Private void dgv_zy_cellcontentclick (Object sender, datagridviewcelleventargs E)
{
Int COUNT = convert. toint16 (dgv_zy.rows.count.tostring ());
For (INT I = 0; I <count; I ++)
{
{
Datagridviewcheckboxcell checkcell = (datagridviewcheckboxcell) dgv_zy.rows [I]. cells ["cb_check"]; {
Boolean flag = convert. toboolean (checkcell. value );
If (flag = true) // find the selected data row
{
Checkcell. value = false;
}
Continue;
}
}



3. Obtain the selected data
Int COUNT = convert. toint32 (dgv_zy.rows.count.tostring ());
For (INT I = 0; I <count; I ++)
{
// If the dview is editable, submit the data. Otherwise, the row in the editing status cannot be obtained.
Dgv_zy. Endedit ();
Datagridviewcheckboxcell checkcell = (datagridviewcheckboxcell) dgv_zy.rows [I]. cells ["cb_check"];
Boolean flag = convert. toboolean (checkcell. value );
If (flag = true) // find the selected data row
{
// Obtain data items from the datagridview
String z_zcode = dgv_zy.rows [I]. cells [0]. value. tostring (). Trim ();
//...................................... ..}
}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/songkexin/archive/2009/12/03/4934143.aspx

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.