问题描述
大家好,
请参见下面的代码:
hi all,
please see the code below:
Dim ComValue As String
If cmbMonth.SelectedItem = "" Then
MessageBox.Show("Please select Month To check", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
For i As Integer = 0 To Val(cmbRegNo.Items.Count - 1)
ComValue = cmbRegNo.Items(i)
CheckDepositedFees(cmbMonth.SelectedItem, ComValue)
If k = "shiv" Then
cmbRegNo.Items.Remove(cmbRegNo.Items(i))
End If
Next
在给定的代码中,cmbRegNo已被数据库中的函数填充,因此我们没有其range(count).我正在调用另一个名为"checkDepositedFees"的函数,如果找到数据,则将结果为(k ="shiv"),然后我要从cmbRegNo中删除该RegNo.但它给我错误,因为从cmbRegNo中删除了项目.我该如何解决该运行时错误(InvalidArgument =值"5"对"index"无效.参数名称:index)请尽快帮助我.
In the given code cmbRegNo has been filled with a function from database so we don''t have its range(count). I''m Calling another function called "checkDepositedFees" If data found then it will Result (k= "shiv") and then I want to remove that RegNo from cmbRegNo. but its gives me error because Items removed from cmbRegNo. how Can I solve that run time error(InvalidArgument=Value of ''5'' is not valid for ''index''. Parameter name: index) please help me soon.
推荐答案
Private Sub RemoveDataB()
Dim sTmp As String = String.Empty, i As Integer = 0, j As Integer
Dim oItem As Object = Nothing
sTmp = "Items to remove:" & vbCr
j = Me.ComboBox1.Items.Count - 1
Do While i < j
oItem = Me.ComboBox1.Items(i)
If oItem.ToString Like "Ship*" Then
sTmp = sTmp & oItem.ToString & vbCr
Me.ComboBox1.Items.Remove(oItem)
i = i - 1
j = j - 1
End If
i = i + 1
Loop
MsgBox(sTmp,MsgBoxStyle.Information,"Info...")
End Sub
这篇关于使用For循环从ComboBox中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!