纠正此错误-"InvalidArgument =值'0'对于'索引'无效.参数名称:索引“ [英] Correct This Error-"InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index"

查看:90
本文介绍了纠正此错误-"InvalidArgument =值'0'对于'索引'无效.参数名称:索引“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub lvdisplay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvdisplay.SelectedIndexChanged
       Dim sno As String
       TripSheet.Show()
       TripSheet.MdiParent = Home
       sno = lvdisplay.SelectedItems(0).SubItems(0).Text
       TripSheet.cb_Sno.Text = sno
       Call TripSheet.display()
       TripSheet.cb_Sno.Focus()
   End Sub




我使用此代码从列表视图中选择项目,并在表单中显示相应的记录.

首先,我从列表视图中选择该项目意味着它可以正确显示...接下来,我从列表视图中选择另一个项目意味着我遇到了此错误...

提出想法来纠正此问题..................................




I used this code for select the item from the list view and display the corresponding records in the form.

First i choose the item from the list view means it displays correctly... Next i choose another item from the list view means i got this error...

Give idea to rectify this..................................

推荐答案

像往常一样:更改选择会导致两个(数量:2)SelectedIndexChanged事件.撤消旧选择并且未选择任何项目时,将触发第一个事件-lvdisplay.SelectedItems目前不包含任何元素,并且lvdisplay.SelectedItems(0)不存在!选择新项目时会触发第二个事件.
发生错误是因为您的代码是在第一个事件中执行的,而您假定自己在第二个事件中.
只需检查:
if (lvdisplay.SelectedItems.Count > 0)
As usual: changing the selection causes TWO (in numbers: 2) SelectedIndexChanged events. The first event is fired when the old selection was undone, and no item is selected - lvdisplay.SelectedItems does not contain any elements at this moment, and lvdisplay.SelectedItems(0) does not exist! The second event is fired when the new item is selected.
Your error occurs because your code is executed with the first event, whilst you assume you are at the second event.
Simply check:
if (lvdisplay.SelectedItems.Count > 0)


这篇关于纠正此错误-"InvalidArgument =值'0'对于'索引'无效.参数名称:索引“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆