<span style="font-family: 'ms shell dlg'; font-size: 14px; line-height: 28px;">获取总行数:dataGridView1.Rows.Count;</span><br style="clear: both; font-family: 'ms shell dlg'; font-size: 14px; line-height: 28px;" /><span style="font-family: 'ms shell dlg'; font-size: 14px; line-height: 28px;">获取当前选中行索引:int i = this.dataGridView1.CurrentRow.Index;</span><br style="clear: both; font-family: 'ms shell dlg'; font-size: 14px; line-height: 28px;" /><span style="font-family: 'ms shell dlg'; font-size: 14px; line-height: 28px;">获取当前选中列索引:int j = this.dataGridView1.CurrentCell.ColumnIndex;</span>
private void DataGrid1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)DataGrid1.CurrentRow.Cells["cb_check"];
Boolean flag = Convert.ToBoolean(checkCell.Value);
checkCell.Value = (!flag);
}
//通过点击事件调用下面的方法
private void CheckBox_GetData()
{
List<string> list_id = new List<string>();
if (DataGrid1.Rows.Count > 0)
{
for (int i = 0; i < DataGrid1.Rows.Count; i++)
{
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)DataGrid1.Rows[i].Cells["cb_check"];
Boolean flag = Convert.ToBoolean(checkCell.Value);
if (flag)
{
list_id.Add(DataGrid1.Rows[i].Cells["SID"].Value.ToString());
}
}
}
string str123 = string.Join(",", list_id.ToArray());
MessageBox.Show(str123);
}