The checkbox column of the datagridview check. the status value is obtained in real time when the checkbox status is modified.

Source: Internet
Author: User

I don't know if you have any experience like this. When you click or cancel the checkbox column of the datagridview dview, it is difficult to determine whether the status is selected or not, which makes it difficult to perform other operations, the solution is listed below:

 

The CurrentCellDirtyStateChanged and CellValueChanged events of the dview are mainly used.

The CurrentCellDirtyStateChanged event submits changes to the checkbox status.

The CellValueChanged event is used to perform other operations after the status is submitted, that is, after the cell value is changed. Here, the true or false status of the checkbox column is set as the tooptiptext attribute to the button column in the same row.

 

CurrentCellDirtyStateChanged Event code:

Code
Private void dataGridView1_CurrentCellDirtyStateChanged (object sender, EventArgs e)
{
If (this. dataGridView1.IsCurrentCellDirty) // you have not submitted any more. // modify
{
This. Maid. Commit );
}
}

 

CellValueChanged Event code:

Code
Private void maid (object sender, maid e)
{
If (this. dataGridView1.Columns [e. ColumnIndex]. Name. Equals ("gender "))
{
Maid cell dgvButtonCell = this. Maid [e. RowIndex]. Cells ["btn"] as maid cell; // get the button Column cell
Maid cell dgvCheckBoxCell = this. Maid [e. RowIndex]. Cells [e. ColumnIndex] as maid cell; // get the cell in the checkbox Column
DgvButtonCell. ToolTipText = dgvCheckBoxCell. Value. ToString (); // Value assignment
}
}

 

 

 

 

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.