Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataGridView SelectedRows返回null_C#_Winforms_Datagridview - Fatal编程技术网

C# DataGridView SelectedRows返回null

C# DataGridView SelectedRows返回null,c#,winforms,datagridview,C#,Winforms,Datagridview,我不明白为什么SelectedRows.ToString()即使在查看Microsoft的最新版本时也返回空值 这是我的代码: DataGridViewRow row = dgvTransaction.SelectedRows[0]; string tempcid = row.Cells[0].ToString(); dbop.delete_command(String.Format("DELETE FROM CERAMIC WHERE CERAMIC_ID = '{0}'",tempcid))

我不明白为什么
SelectedRows.ToString()
即使在查看Microsoft的最新版本时也返回空值

这是我的代码:

DataGridViewRow row = dgvTransaction.SelectedRows[0];
string tempcid = row.Cells[0].ToString();
dbop.delete_command(String.Format("DELETE FROM CERAMIC WHERE CERAMIC_ID = '{0}'",tempcid));
这里有什么问题吗?
DataGridView
源代码是来自数据库的
DataSet
,我也将选择模式更改为全行选择

我一直在搜索有关选定行的堆栈溢出的问题,但没有一行回答我的问题。也许一点回答会对我有帮助^^

编辑1

这对我很有帮助,谢谢mate编辑了我的代码

DataGridViewRow row = dgvTransaction.SelectedRows[0];
string tempcid = row.Cells[0].Value.ToString();
dbop.delete_command(String.Format("DELETE FROM CERAMIC WHERE CERAMIC_ID = '{0}'",tempcid));

dgvTransaction.Rows.RemoveAt(row.Index);
dgvTransaction.Refresh();

它是有效的。谢谢

看一看这个问题可能会对你有所帮助:那个代码是什么事件处理程序?@Balah:它在删除事件处理程序上,删除是按钮