【发布时间】:2011-05-18 08:03:12
【问题描述】:
这可能与谁有关,我已经搜索了相当长的时间,以找出解决此错误的方法
“已删除的行信息无法通过行访问”
我了解,一旦从数据表中删除了一行,就无法以典型的方式访问它,这就是我收到此错误的原因。最大的问题是我不确定如何获得我想要的结果,我将在下面概述。
基本上,当“dg1”中的一行被删除时,它下面的行会代替已删除的行(显然),从而继承已删除的行索引。此方法的目的是替换和重置将删除的行占据位置的行索引(通过从数据集中的相应值中获取)以及索引值。
现在我只是使用一个标签 (lblText) 来尝试从进程中获取响应,但是当最后一个嵌套的 if 语句尝试比较值时它会崩溃。
代码如下:
void dg1_Click(object sender, EventArgs e)
{
rowIndex = dg1.CurrentRow.Index; //gets the current rows
string value = Convert.ToString(dg1.Rows[rowIndex].Cells[0].Value);
if (ds.Tables[0].Rows[rowIndex].RowState.ToString() == "Deleted")
{
for (int i = 0; i < dg1.Rows.Count; i++)
{
if (Convert.ToString(ds.Tables[0].Rows[i][0].ToString()) == value)
// ^ **where the error is occurring**
{
lblTest.Text = "Aha!";
//when working, will place index of compared dataset value into rowState, which is displaying the current index of the row I am focussed on in 'dg1'
}
}
}
提前感谢您的帮助,我确实进行了搜索,如果通过简单的谷歌搜索很容易弄清楚,那么请允许自己反复讨厌我,因为我确实尝试过。
- gc
【问题讨论】:
标签: c# datagrid dataset runtime