csharp 从DataGridView获取选定的行

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 从DataGridView获取选定的行相关的知识,希望对你有一定的参考价值。

foreach (DataGridViewRow r in dataGridView1.SelectedRows)
{
   //Code to add selected row to new datagrid.
   //Important to note that dataGridView2.Rows.Add(r) will not work 
   //because each row can only belong to one data grid.  You'll have 
   //to create a new Row with the same info for an exact copy
}

foreach (DataGridViewRow r in dataGridView1.SelectedRows)
{
  // If you wanted to move the items from one DataGridViewRow to the other 
  // [so that they could only exist in one list at a time] you could do this.
  dataGridView1.Rows.Remove(r);
  dataGridView2.Rows.Add(r);
}

以上是关于csharp 从DataGridView获取选定的行的主要内容,如果未能解决你的问题,请参考以下文章

从 DataGridView 选定的单元格中获取文本

从datagridview中选定行的值的ID中获取名称

获取 DataGridView 中选定行的单元格内容

将数据从组合框获取到 datagridview

如何获取 Datagridview Combobox 选定项的 TEXT?

如何在 DataGridView 中获取选定的 DataRow?