C # Winform DataGridViewCheckBoxColumn use in a DataGridView

C # Winform DataGridViewCheckBoxColumn use in a DataGridView

Category: WinForm 2627 people read comments (2) Collection Report

The following describes a DataGridView Winform DataGridViewCheckBoxColumn in use:

 

DataGridViewCheckBoxColumn the CheckBox is selected or

  In determining the DataGridView CheckBox selected column when [0] exist with DataGridViewRow.Cells .FormattedValue.ToString () == "True" when the statement is a problem, when we click on CheckBox, the results show is not selected, but if we click when other cells, the results show selected. And with DataGridViewRow.Cells [0] .EditedFormattedValue.ToString () == "True" when the statement is selected by the state anyway.

Why is there such a result?

  The reason: that is the result of the operation FormattedValue submitted, and EditedFormattedValue is the current result, regardless of whether the results have been submitted.

     Therefore, the use DataGridViewRow.Cells [0] .EditedFormattedValue.ToString () == "True" Analyzing select suitable

[c-sharp] view plain copy print ?
  1. if (dgvDownloadList.Rows.Count > 0)  
  2. {  
  3.     for (int i = 0; i < dgvDownloadList.Rows.Count; i++)  
  4.     {  
  5.         string _selectValue = dgvDownloadList.Rows[i].Cells["Column1"].EditedFormattedValue.ToString();  
  6.         if (_selectValue == "True")  
  7.            // If the CheckBox is selected, then write the code in here to continue   
  8.      }  
  9. }   

if (dgvDownloadList.Rows.Count> 0) {for (int i = 0; i <dgvDownloadList.Rows.Count; i ++) {string _selectValue = dgvDownloadList.Rows [i] .Cells [ "Column1"] EditedFormattedValue.ToString (. ); if (_selectValue == "True") // If the CheckBox is checked, continue to write code here}}

 

 

DataGridViewCheckBoxColumn set the CheckBox checked by default

   ((DataGridViewCheckBoxCell)dgvDownloadList.Rows[i].Cells["Column1"]).Value = true;

 

DataGridViewCheckBoxColumn the first time to get checked in CheckBox

  When you click a checkbox or cancel datagridview column, the more difficult to obtain its status is checked or unchecked, then good for other operations, the following list of its solution: 

  CommitEdit: will be submitted to the current cell changes to the data cache without ending edit mode 

[c-sharp] view plain copy print ?
  1. dgvDownloadList.CurrentCellDirtyStateChanged += new EventHandler(dgvDownloadList_CurrentCellDirtyStateChanged);  
  2.  dgvDownloadList.CellValueChanged += new DataGridViewCellEventHandler(dgvDownloadList_CellValueChanged);  
  3.     
  4. void dgvDownloadList_CurrentCellDirtyStateChanged(object sender, EventArgs e)  
  5. {  
  6.      if (dgvDownloadList.IsCurrentCellDirty)  
  7.      {  
  8.          dgvDownloadList.CommitEdit(DataGridViewDataErrorContexts.Commit);  
  9.      }              
  10. }  
  11.     
  12. void dgvDownloadList_CellValueChanged(object sender, DataGridViewCellEventArgs e)  
  13. {  
  14.      if (dgvDownloadList.Rows.Count > 0)  
  15.      {  
  16.          for (int i = 0; i < dgvDownloadList.Rows.Count; i++)  
  17.          {  
  18.              string _selectValue = dgvDownloadList.Rows[i].Cells["Column1"].EditedFormattedValue.ToString();  
  19.              if (_selectValue == "True")  
  20.                  // If the CheckBox is selected, then write the code in here to continue   
  21.          }  
  22.       }  
  23. }  

dgvDownloadList.CurrentCellDirtyStateChanged += new EventHandler(dgvDownloadList_CurrentCellDirtyStateChanged); dgvDownloadList.CellValueChanged += new DataGridViewCellEventHandler(dgvDownloadList_CellValueChanged); void dgvDownloadList_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (dgvDownloadList.IsCurrentCellDirty) { dgvDownloadList.CommitEdit(DataGridViewDataErrorContexts.Commit); } } void dgvDownloadList_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (dgvDownloadList.Rows.Count > 0) { for (int i = 0; i < dgvDownloadList.Rows.Count; i++) { string _selectValue = dgvDownloadList.Rows[i].Cells["Column1"].EditedFormattedValue.ToString(); if (_selectValue == "True") //如果CheckBox已选中,则在此处继续编写代码 } } }

 

Reproduced in: https: //www.cnblogs.com/baishiying/archive/2012/09/13/2683242.html

The following describes a DataGridView Winform DataGridViewCheckBoxColumn in use:

 

DataGridViewCheckBoxColumn the CheckBox is selected or

  In determining the DataGridView CheckBox selected column when [0] exist with DataGridViewRow.Cells .FormattedValue.ToString () == "True" when the statement is a problem, when we click on CheckBox, the results show is not selected, but if we click when other cells, the results show selected. And with DataGridViewRow.Cells [0] .EditedFormattedValue.ToString () == "True" when the statement is selected by the state anyway.

Why is there such a result?

  The reason: that is the result of the operation FormattedValue submitted, and EditedFormattedValue is the current result, regardless of whether the results have been submitted.

     Therefore, the use DataGridViewRow.Cells [0] .EditedFormattedValue.ToString () == "True" Analyzing select suitable

[c-sharp] view plain copy print ?
  1. if (dgvDownloadList.Rows.Count > 0)  
  2. {  
  3.     for (int i = 0; i < dgvDownloadList.Rows.Count; i++)  
  4.     {  
  5.         string _selectValue = dgvDownloadList.Rows[i].Cells["Column1"].EditedFormattedValue.ToString();  
  6.         if (_selectValue == "True")  
  7.            // If the CheckBox is selected, then write the code in here to continue   
  8.      }  
  9. }   

if (dgvDownloadList.Rows.Count> 0) {for (int i = 0; i <dgvDownloadList.Rows.Count; i ++) {string _selectValue = dgvDownloadList.Rows [i] .Cells [ "Column1"] EditedFormattedValue.ToString (. ); if (_selectValue == "True") // If the CheckBox is checked, continue to write code here}}

 

 

DataGridViewCheckBoxColumn set the CheckBox checked by default

   ((DataGridViewCheckBoxCell)dgvDownloadList.Rows[i].Cells["Column1"]).Value = true;

 

DataGridViewCheckBoxColumn the first time to get checked in CheckBox

  When you click a checkbox or cancel datagridview column, the more difficult to obtain its status is checked or unchecked, then good for other operations, the following list of its solution: 

  CommitEdit: will be submitted to the current cell changes to the data cache without ending edit mode 

[c-sharp] view plain copy print ?
  1. dgvDownloadList.CurrentCellDirtyStateChanged += new EventHandler(dgvDownloadList_CurrentCellDirtyStateChanged);  
  2.  dgvDownloadList.CellValueChanged += new DataGridViewCellEventHandler(dgvDownloadList_CellValueChanged);  
  3.     
  4. void dgvDownloadList_CurrentCellDirtyStateChanged(object sender, EventArgs e)  
  5. {  
  6.      if (dgvDownloadList.IsCurrentCellDirty)  
  7.      {  
  8.          dgvDownloadList.CommitEdit(DataGridViewDataErrorContexts.Commit);  
  9.      }              
  10. }  
  11.     
  12. void dgvDownloadList_CellValueChanged(object sender, DataGridViewCellEventArgs e)  
  13. {  
  14.      if (dgvDownloadList.Rows.Count > 0)  
  15.      {  
  16.          for (int i = 0; i < dgvDownloadList.Rows.Count; i++)  
  17.          {  
  18.              string _selectValue = dgvDownloadList.Rows[i].Cells["Column1"].EditedFormattedValue.ToString();  
  19.              if (_selectValue == "True")  
  20.                  // If the CheckBox is selected, then write the code in here to continue   
  21.          }  
  22.       }  
  23. }  

dgvDownloadList.CurrentCellDirtyStateChanged += new EventHandler(dgvDownloadList_CurrentCellDirtyStateChanged); dgvDownloadList.CellValueChanged += new DataGridViewCellEventHandler(dgvDownloadList_CellValueChanged); void dgvDownloadList_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (dgvDownloadList.IsCurrentCellDirty) { dgvDownloadList.CommitEdit(DataGridViewDataErrorContexts.Commit); } } void dgvDownloadList_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (dgvDownloadList.Rows.Count > 0) { for (int i = 0; i < dgvDownloadList.Rows.Count; i++) { string _selectValue = dgvDownloadList.Rows[i].Cells["Column1"].EditedFormattedValue.ToString(); if (_selectValue == "True") //如果CheckBox已选中,则在此处继续编写代码 } } }

 

Guess you like

Origin blog.csdn.net/weixin_34050427/article/details/93440055
Recommended