C # Check winform dview

Source: Internet
Author: User

In the Web program, the data source binding control GridView contains a template column. It is very easy to obtain whether the check box is selected and the row where the check box is located. The classic code is as follows:
For (int I = 0; I <gvList. Rows. Count; I ++)
{
If (CheckBox) gvList. Rows [I]. Cells [0]. FindControl ("chkID"). Checked)
{}
}
However, the DataGridView control in WinForm cannot be used in this way. The DataGridView control does not have a free template column at all. Some have six built-in template columns, and the check box is one of them. To obtain whether or not the check box is selected and other values corresponding to the selected row cannot be implemented in this way in the Web program, but must be determined by the Value attribute of Cells in the DataGridView control.

(In WinForm, The DataGridView control deletes multiple records through the check box.) The Code is as follows:
Private void btnDelete_Click (object sender, EventArgs e)
{
String strNames = "you selected :";
For (int I = 0; I <dgvList. Rows. Count; I ++)
{
If (dgvList. Rows [I]. Cells [0]. Value! = Null) // determine whether the check box for this row exists
{
If (dgvList. Rows [I]. Cells [0]. Value. ToString () = "True") // you can check whether the check box is selected.
{
StrNames + = dgvList. Rows [I]. Cells [2]. Value. ToString () + "";
}
}
}
MessageBox. Show (strNames, "system prompt", MessageBoxButtons. OK, MessageBoxIcon. Information );
}
Running result:

Reposted from the network. The source is unknown !!

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.