C# DataGridView控件选中行获取其值

DataGridView的几个基本操做:
一、得到某个(指定的)单元格的值:
dataGridView1.Row[i].Cells[j].Value;
二、得到选中的总行数:
dataGridView1.SelectedRows.Count;
三、得到当前选中行的索引:
dataGridView1.CurrentRow.Index;
四、得到当前选中单元格的值:
dataGridView1.CurrentCell.Value;
五、取选中行的数据
string[] str = new string[dataGridView.Rows.Count];
for(int i;i<dataGridView1.Rows.Count;i++)
{
if(dataGridView1.Rows[i].Selected == true)
{
str[i] = dataGridView1.Rows[i].Cells[1].Value.ToString();
}
}
七、获取选中行的某个数据
int a = dataGridView1.SelectedRows.Index;
dataGridView1.Rows[a].Cells[“你想要的某一列的索引,想要几就写几”].Value;索引

得到某个(指定的)单元格的值: dataGridView1.Row[i].Cells[j].Value; Row[i] 应该是Rows[i]string

int a=dataGridView1.CurrentRow.Index;
string str=dataGridView1.Row[a].Cells[“strName”].Value.Tostring();class

selectedRows[0]当前选中的行
.cell[列索引].values 就是当前选中行的某个单元格的值select

DataGridView1.SelectedCells(0).Value.ToString 取当前选择单元内容
DataGridView1.Rows(e.RowIndex).Cells(2).Value.ToString 当前选择单元第N列内容数据