从组合框中删除项目时出错 [英] error when remove item from combobox
本文介绍了从组合框中删除项目时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一段代码,我可以删除第一个值但是失败并发出通知
InvalidArgument =值'0'无效对于'index'。
参数名称:index
私人 Sub ComboBox1_KeyDown( ByVal sender As 系统。对象, ByVal e As System.Windows.Forms.KeyEventArgs)句柄 ComboBox1.KeyDown
如果 ComboBox1。 Items.Count> 0 然后
如果 e .KeyCode = Keys.Delete 然后
ComboBox1.Items.Remove(ComboBox1.SelectedItem)
' 或
' ComboBox1。 Items.RemoveAt(ComboBox1.SelectedIndex)
结束 如果
结束 如果
结束 < span class =code-keyword> Sub
感谢帮助!
解决方案
删除第一项后,所选索引指向0,这不是有效索引。
将所选项设置为有效值,然后再次删除。
我声明 如果 ComboBox1。 SelectedIndex> 0 然后
可以不 delete 第一个值
hi all,
I have a piece of code, I can delete the first value but fails and give notice
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
Private Sub ComboBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown If ComboBox1.Items.Count > 0 Then If e.KeyCode = Keys.Delete Then ComboBox1.Items.Remove(ComboBox1.SelectedItem) 'or 'ComboBox1.Items.RemoveAt(ComboBox1.SelectedIndex) End If End If End Sub
thank help !解决方案After you delete the first item, selected index points to 0 which is not a valid index.
Set the selected item to a valid value and then delete again.
I declare If ComboBox1.SelectedIndex > 0 Then Can not delete the first value
这篇关于从组合框中删除项目时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文