在使用DataGridView控件时,可以通过以下方法来获取DataGridViewRow的第一个值,而不是选择整行:
// 假设DataGridView控件的名称为dataGridView1
DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];
string firstCellValue = selectedRow.Cells[0].Value.ToString();
// 假设DataGridView控件的名称为dataGridView1
DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];
string firstCellValue = selectedRow[0].Value.ToString();
请注意,上述代码示例假设你已经选中了一行数据,并将其存储在selectedRow变量中。如果你想获取多选行的第一个单元格值,你可以使用循环来遍历所选行的集合。
希望以上解决方法对你有帮助!