C# 需要DataGridView UserDeletedRow事件处理程序中的帮助
抱歉,如果这看起来有点不专业,但我不知道这里发生了什么,这让我发疯 我有一个DataGridView,其中包含如下数据:- 我想做的是,每当用户删除一行(或条目)时,我希望它下面的所有行相应地更新其SrNo和Balance字段,我已在UserDeletedRow事件处理程序函数中为其编写了以下代码:- (请注意,删除第一行是禁用的) 没有返回正确的值(我想是这样),因为当我在If条件上放置断点时,我看到了这一点 这个在观察名单上吗 我们可以看到,所选行(或当前行)是索引编号5,但在观察列表上显示为4,这是我的问题的根源C# 需要DataGridView UserDeletedRow事件处理程序中的帮助,c#,.net,datagridview,C#,.net,Datagridview,抱歉,如果这看起来有点不专业,但我不知道这里发生了什么,这让我发疯 我有一个DataGridView,其中包含如下数据:- 我想做的是,每当用户删除一行(或条目)时,我希望它下面的所有行相应地更新其SrNo和Balance字段,我已在UserDeletedRow事件处理程序函数中为其编写了以下代码:- (请注意,删除第一行是禁用的) 没有返回正确的值(我想是这样),因为当我在If条件上放置断点时,我看到了这一点 这个在观察名单上吗 我们可以看到,所选行(或当前行)是索引编号5,但在观察列表
非常感谢您的帮助。您能尝试使用SelectedIndex而不是当前行吗?如果(dataGridView1.SelectedIndex!=dataGridView1.Rows.Count-1)@GaAd没有selectindex和selectedrows[0]这样的属性。index返回一个errorOk,表示该行已被删除。我认为您希望在删除行之前操作表。您是否尝试过其他活动,如在RowDeleting上?受保护的void GridView1_rowdeleding(对象发送方,GridViewDeleteEventArgs e)@GaAd没有rowdeleding这样的事件,但是有一个名为userrowdeleding的事件,我应该试试吗?您正在asp.net中使用一个gridview和c#。gridview选项卡中应该有一个事件,
private void dataGridView1_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
{
if(dataGridView1.CurrentRow.Index != dataGridView1.Rows.Count - 1)
{
for (int i = dataGridView1.CurrentRow.Index; i < dataGridView1.Rows.Count - 1; i++)
{
dataGridView1.Rows[i].Cells[0].Value = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value) - 1;
int a = dataGridView1.Rows[i].Cells[2].Value == DBNull.Value ? 0 : Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
int b = dataGridView1.Rows[i].Cells[3].Value == DBNull.Value ? 0 : Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);
dataGridView1.Rows[i].Cells[4].Value = (a + Convert.ToInt32(dataGridView1.Rows[i - 1].Cells[4].Value)) - b;
}
}
}
dataGridView1.CurrentRow.Index