到目前为止,我所看到的是将整行复制到另一个datagridview的方法,但是我想在我向下拖动鼠标时仅复制突出显示的(选定)单元格的值(就像8x3网格一样)。你会怎么做?这是在Windows窗体.net框架上。当我尝试将单元格值传输到datagridview2中的单元格时,我收到错误。错误显示“索引超出范围。必须是非负数且小于集合的大小”
以下是参考https://youtu.be/MK-vfM2uqY4
private void button1_Click(object sender, EventArgs e){
if (dataGridView1.SelectedCells.Count == 24){
foreach(DataGridViewCell cell in dataGridView1.SelectedCells){
for(int i=0; i<=8; i++){
for(int j=0; j<= 3; j++){
if (i == 0 || j == 0)
dataGridView2.Rows[i].Cells[j].Value = null;//error occurs
else
dataGridView2.Rows[i].Cells[j].Value = cell.Value; //error occurs
}
}
}
}
else
MessageBox.Show("Select the correct number of cells");
}