问题遇到的现象和发生背景
在datagridview中添加了复选框,现在想要把选中的数据填入textbox中
问题相关代码,请勿粘贴截图
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
//不是序号列和标题列时才执行
if (e.RowIndex != -1 && e.ColumnIndex != -1)
{
//checkbox 勾上
if ((bool)dataGridView1.Rows[e.RowIndex].Cells[0].EditedFormattedValue == true)
{
//选中改为不选中
this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = false;
}
else
{
//不选中改为选中
this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = true;
}
}
}
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
如上图,现在想要达到的结果就是textbox中,除了数量是选中的几列中的数量相加,其他的都显示datagridview选中的第一行的数据