积极答复者
VB2005中的死循环的问题

问题
-
语句:
Private Sub UltraGrid1_AfterCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles UltraGrid1.AfterCellUpdate
TryIf Me.UltraGrid1.ActiveRow.Cells("jf").Value <> "" Then’‘’当当前行jf单元格的值不等于空的时候
Me.UltraGrid1.ActiveRow.Cells("df").Value = "" ’‘’则当前行的df单元格的值等于空
Exit Sub
End IfIf Me.UltraGrid1.ActiveRow.Cells("df").Value <> "" Then’‘’当当前行df单元格的值不等于空的时候
Me.UltraGrid1.ActiveRow.Cells("jf").Value = "" ’‘’则当前行jf单元格的值等于空End If
Exit Sub
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Information, "try")
End Try
End Sub红色位置为死循环出错的地方
浅蓝色为注释
请feiyun0112帮我看看..该怎么改????谢谢
全部回复
-
1.请feiyun0112老师帮我转换一下这段代码:(转换成vb语法)
if (this.ultraGrid1.Rows.Count <= 0)
{
MessageInfo.ShowMessage("m_system_client_0009");
return ;
}
#endregion
if (this.ultraGrid1.ActiveRow != null)
{
this.ultraGrid1.ActiveRow.Selected = true;
}
if (MessageInfo.ShowMessage("m_system_client_0003", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
bool blnDeleted = false;
for (int i = 0; i < this.ultraGrid1.Rows.Count; i++)
{
if (this.ultraGrid1.Rows.Selected || this.ultraGrid1.Rows
.IsActiveRow)
{
if (this.ultraGrid1.Rows.Delete(false))
{
i--;
}
blnDeleted = true;
}
}
if (!blnDeleted)
{
MessageInfo.ShowMessage("m_system_client_0009");
}
}2.我加进以后成这样的代码,但进入断点事件后不经过FOR 这个语句里来
Private Sub UltraGrid1_AfterCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles UltraGrid1.AfterCellUpdate
Try
Dim i As Integer
Dim j As IntegerIf Me.UltraGrid1.Rows(i).Cells("jf").Value = "" Then
For i = 1 To (Me.UltraGrid1.Rows.Count - 1)Me.UltraGrid1.Rows(i).Cells("df").Value = ""
Next
End IfIf Me.UltraGrid1.Rows(i).Cells("df").Value = "" Then
For j = 1 To (Me.UltraGrid1.Rows.Count - 1)
Me.UltraGrid1.Rows(j).Cells("jf").Value = ""
Next
End If
Exit Sub
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Information, "try")
End Try红色的部分,断点不经过,而且我的借方金额和贷方金额里都有了数据,请帮我看看该怎么写?这几天脑袋都大了
谢谢!
-
-
rego 写: 语句:
Private Sub UltraGrid1_AfterCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles UltraGrid1.AfterCellUpdate
TryIf Me.UltraGrid1.ActiveRow.Cells("jf").Value <> "" Then’‘’当当前行jf单元格的值不等于空的时候
Me.UltraGrid1.ActiveRow.Cells("df").Value = "" ’‘’则当前行的df单元格的值等于空
Exit Sub
End IfIf Me.UltraGrid1.ActiveRow.Cells("df").Value <> "" Then’‘’当当前行df单元格的值不等于空的时候
Me.UltraGrid1.ActiveRow.Cells("jf").Value = "" ’‘’则当前行jf单元格的值等于空End If
Exit Sub
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Information, "try")
End Try
End Sub红色位置为死循环出错的地方
浅蓝色为注释
你说要加个判断,我试了很多方法都不行,我就加了个for next,我自己都不知道我在写什么?
但我的意图是清楚的,即:上面注释
i 为行数吧
feiyun0112老师您就把正确代码告诉我吧.............这个问题我都想了很多天了..一直没明白该怎么写?
-
修改之前先记住当前的cellindex,我不知道有没有activecell属性
Code SnippetPrivate Sub UltraGrid1_AfterCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles UltraGrid1.AfterCellUpdate
if cellindex=Me.UltraGrid1.ActiveRow.Cells("jf").index then
TryIf Me.UltraGrid1.ActiveRow.Cells("jf").Value <> "" Then’‘’当当前行jf单元格的值不等于空的时候
Me.UltraGrid1.ActiveRow.Cells("df").Value = "" ’‘’则当前行的df单元格的值等于空
Exit Sub
End IfIf Me.UltraGrid1.ActiveRow.Cells("df").Value <> "" Then’‘’当当前行df单元格的值不等于空的时候
Me.UltraGrid1.ActiveRow.Cells("jf").Value = "" ’‘’则当前行jf单元格的值等于空End If
Exit Sub
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Information, "try")
End Tryend if
End Sub -
feiyun0112 写: 我只是举隔例子
主要就是判断当前cellindex是不是"jf"列的index,是就表示是jf列触发的
这样写也不对啊
dim cellindex as integer
if cellindex=me.ultragrid1.activecell.value then
if not ultragrid1.activerow.cell("jf").value is nothing then
me.ultragrid1.activerow.cell("df").value=""
end if
if not ultragrid1.activerow.cell("df").value is nothing then
me.ultragrid1.activerow.cell("jf").value=""
end if
end if -
-
feiyun0112 写: value肯定不行
一定有属性可以得到的columnindex,cellindex,你看看帮助
Dim cellindex As Integer
cellindex = Me.UltraGrid1.ActiveCell.Column.Index
If cellindex = Me.UltraGrid1.ActiveRow.Cells("jf").Column.Index Then
Me.UltraGrid1.ActiveRow.Cells("df").Value = ""
End If
If cellindex = Me.UltraGrid1.ActiveRow.Cells("df").Column.Index Then
Me.UltraGrid1.ActiveRow.Cells("jf").Value = ""
End If
有这样的属性
这样写可以吗?