A small question about C # DataGridView Select All and Cancel

Source: Internet
Author: User

I was in front of the game is a C + + now in C # to do some unfamiliar may understand the wrong welcome to the paper

private void Btnselectorcancel_click (object sender, EventArgs e)
{
BOOL isChecked = false;
foreach (DataGridViewRow gvrow in Dgvdata.rows)
{
String strstate = Gvrow.cells[dgvdata.columncount-1]. Value.tostring ();
if (! ( Strstate.compareto ("True") = = 0 | | Strstate.compareto ("true") = = 0))
{
IsChecked = true;
Break
}
}
for (int i = 0;i < Dgvdata.rowcount;++i)
{
Dgvdata.rows[i]. CELLS[DGVDATA.COLUMNCOUNT-1]. Value = isChecked;
}
}

There's a problem with this code. When one of my cells is clicked and then click to select All, the view of the cell has not changed. I hit the log constantly debugging to find the data is right guess is the view is not updated or the data cache problem.

So I looked at the related properties of DataGridView, which had an attribute CurrentCell. This property will become the cell when you click on a cell. At this point we only need to set the value of our DataGridView CurrentCell to null at the start of the Select button click event. The problem is solved. In fact, there is another way to manipulate the data source. This way everyone should understand this and not explain it.

A small question about C # DataGridView Select All and Cancel

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.