C# 如何获取第一个datagridview';如果未选择,则为s单元格值?

C# 如何获取第一个datagridview';如果未选择,则为s单元格值?,c#,C#,我想获取第一个datagridview的值,而不使用选择模式:fullselectedrow。下面的例子不起作用 MessageBox.Show(AppointmentGrid.SelectedRows[0].Cells[0].Value.ToString()); 我收到以下错误:类型为“System.ArgumentOutOfRangeException”的未处理异常要获取DataGridView中第一个单元格的值: var cellValue = AppointmentGrid.Rows[

我想获取第一个datagridview的值,而不使用选择模式:fullselectedrow。下面的例子不起作用

MessageBox.Show(AppointmentGrid.SelectedRows[0].Cells[0].Value.ToString());

我收到以下错误:类型为“System.ArgumentOutOfRangeException”的未处理异常要获取DataGridView中第一个单元格的值:

var cellValue = AppointmentGrid.Rows[0].Cells[0].Value;
要删除单个选定单元格的行,请执行以下操作:

AppointmentGrid.Rows.RemoveAt(AppointmentGrid.SelectedCells[‌​0].RowIndex);

尽管如此;您确实需要执行一些边界检查,以使索引不超出范围。

关于
MessageBox.Show(AppointmentGrid.Rows[0].Cells[0].Value.ToString())如何?谢谢,成功了。最后一个问题是,如果只选择了一个单元格,如何删除当前行?类似于
AppointGrid.Rows.RemoveAt(AppointGrid.SelectedCells[0].RowIndex)