Add the checkbox dataGridView column, click the checkbox, unable to obtain correct whether the selected state
CheckColumn=new DataGridViewCheckBoxColumn (); CheckColumn. The HeaderText="select"; CheckColumn. Name="select"; DGV. Columns. The Add (checkColumn); Console. WriteLine (DGV. Columns. Count. The ToString ()); DGV. CellMouseClick +=new DataGridViewCellMouseEventHandler ((object sender, DataGridViewCellMouseEventArgs e)=& gt; { If (e.c. with our fabrication: olumnIndex==4)//: why is the column number 4 { //print the line number Console. WriteLine (" index "+" e.R owIndex. The ToString ()); If (e.c. with our fabrication: olumnIndex==4) { Int I="e.R owIndex; Boolean ret.=the Convert ToBoolean (dgv1 Rows [I] Cells [r]. "select" Selected); If (ret) Console. WriteLine (" true "); The else Console. WriteLine (" false "); } } }); CodePudding user response:
Refer to
https://www.cnblogs.com/moss_tan_jun/archive/2011/04/06/2007319.html
CodePudding user response:
Dgv1. Rows [I] Cells [r]. "select"
Value CodePudding user response:
Refer to him, but several events can obtain a correct lines of the checkbox selected,
DGV. CellClick +=dgv_CellClick;
DGV. CellValueChanged +=dgv_CellValueChanged;
DGV. CellMouseClick
The above three are not,
CodePudding user response:
reference number007cool reply: 3/f refer to him, but several events can obtain a correct lines of the checkbox selected, DGV. CellClick +=dgv_CellClick; DGV. CellValueChanged +=dgv_CellValueChanged; DGV. CellMouseClick The above three are not, is less than, or access is wrong?? Breakpoint debugging to see ah CodePudding user response:
refer to the second floor Bridge_go response: dgv1. Rows [I] Cells [r]. "select" Value In the event of an dgv_CellValueChanged have reaction, but always slow a beat, private void dgv_CellValueChanged (object sender, DataGridViewCellEventArgs e) { //print the line number Console. WriteLine (" index "+" e.R owIndex. The ToString ()); If (e.c. with our fabrication: olumnIndex==5) { Int I="e.R owIndex; Boolean ret.=the Convert ToBoolean (dgv1 Rows [I] Cells [r]. "select" Value); If (ret) Console. WriteLine (" true "); The else Console. WriteLine (" false "); } } In turn, uncheck 0-5 lines, and then in turn select 0-5 lines of the check, print is as follows: The index 0 False Index 1 False Index 2 False The index 3 False The index of 4 False The index 0 True Index 1 True Index 2 True The index 3 True Cancel the row 0, no reaction, cancel the first row, print index 0 false, cancel line 2, print index 1 false, and so on, Are there any solution this CodePudding user response:
Tried to do in the case of point quickly capture status is wrong, CodePudding user response:
Selected after a row, point Button, in Buttun_ClickDataGridViewRow row=this. DataGridView1. SelectedRows [0]. The object value=https://bbs.csdn.net/topics/row.Cells [0]. Value; CodePudding user response:
refer to 7th floor wang_peng response: select a row, after some Button, in Buttun_ClickDataGridViewRow row=this. DataGridView1. SelectedRows [0]. The object value=https://bbs.csdn.net/topics/row.Cells [0]. Value; Didn't quite understand what you mean, this is user habit, after each line must be selected, click the checkbox? A two-step? in addition, I found a problem with the above logic click back and forth if the checkbox in the same line, there is no any response, CodePudding user response:
Instead of cell_doubleclick events? CodePudding user response:
private void dataGridView1_CellMouseClick (object sender, DataGridViewCellMouseEventArgs e) { If (e.c. with our fabrication: olumnIndex==2) { Bool isChecked=bool. Parse (this) dataGridView1) Rows [" e.R owIndex]. Cells [2]. The Value. The ToString ()); Enclosing dataGridView1. Rows [" e.R owIndex] Cells [2]. The Value=https://bbs.csdn.net/topics/! IsChecked; } } Try adding a events CodePudding user response:
refer to the eighth floor number007cool response: Quote: refer to 7th floor wang_peng response: select a row, after some Button, in Buttun_ClickDataGridViewRow row=this. DataGridView1. SelectedRows [0]. The object value=https://bbs.csdn.net/topics/row.Cells [0]. Value; Didn't quite understand what you mean, this is user habit, after each line must be selected, click the checkbox? A two-step? in addition, I found a problem with the above logic click back and forth if the checkbox in the same line, there is no any response, First, select the way has 3 kinds, one of which is as long as any one point of the current row cell, even if the selected line So you can click on the checkbox, also is equivalent to the selected line, And just find a event, The code above me in it, No return should may be your code has a problem, have a look at it carefully. Try to put all of the events about dataGridview completely blocked, See also not a problem CodePudding user response:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull