How to obtain the multi-row data selected by the checkbox in the datagridview

Source: Internet
Author: User

This problem occurs during development (winform). C # how to determine whether the checkbox column in The dview datagriis selected, and the cause of the error is C # The type is strictly determined. To avoid detours in the future, let me talk about my ideas and hope to help you.

For (int I = 0; I <dataGridView1.Rows. Count; I ++)
{
If (bool) dataGridView1.Rows [I]. Cells [0]. EditedFormattedValue = true)
{
// TODO
}

}

========================================================== ========================================================== ===

Private void PrintInFo (){
Try
{
Int count = 0;
// Used to save the selected checkbox quantity
// DG_List is the datagridview Control
For (int I = 0; I <DG_List.RowCount; I ++)
{
If (DG_List.Rows [I]. Cells [0]. EditedFormattedValue. ToString () = "True ")
// Check whether the check box is selected.
{
Count ++;
}
}
If (count = 0)
{
MessageBox. Show ("Please select at least one piece of data! "," Prompt ");
Return;
}
Else
{
If (MessageBox. Show (this, "Do you want to update the data? "," Prompt ", MessageBoxButtons. YesNo, MessageBoxIcon. Information). ToString () =" Yes ")
{
For (int I = 0; I <count; I ++)
{
Ps. pexcute ("update cf_prj_certi set FIsPrint = '" + number + "'where fid ='" + DG_List.Rows [I]. cells ["fnn"]. value. toString () + "'"); // Execute SQL
}
} Else
{
Return;
}
}
} Catch (Exception ex)
{
MessageBox. Show (ex. ToString ());
} This. ShowInfo (); // rebind the datagridview.
}

 

========================================================== =

Click the CellMouseClick event in the dataGridView1 event.

Private void maid (object sender, maid e)
{
If (e. ColumnIndex = 6)
{
DataGridView1.Rows [e. RowIndex]. Cells [e. ColumnIndex]. Value = true;
}
}

This problem occurs during development (winform). C # how to determine whether the checkbox column in The dview datagriis selected, and the cause of the error is C # The type is strictly determined. To avoid detours in the future, let me talk about my ideas and hope to help you.

For (int I = 0; I <dataGridView1.Rows. Count; I ++)
{
If (bool) dataGridView1.Rows [I]. Cells [0]. EditedFormattedValue = true)
{
// TODO
}

}

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.