专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

ListBox.Items.Count>0 但執行ListBox.SelectedIndex=0 時確出錯.Index was outside the bounds of the array,该

发布时间:2011-06-23 15:58:49 文章来源:www.iduyao.cn 采编人员:星星草
ListBox.Items.Count>0 但執行ListBox.SelectedIndex=0 時確出錯.Index was outside the bounds of the array
http://community.csdn.net/Expert/topic/5297/5297158.xml?temp=.4631159

我是在一個TabControl中放的ListBox   ,每個TabPage中都有一個ListBox.
在雙擊了當前TabPage中的ListBox後.給所有TabPage中的ListBox設置數據源屬性.

是這樣寫的.但在執行到給不是當前TabPage中的ListBox設置數據源屬性時,執行到
ListBox   .SelectedIndex   =   0(Items.Count> 0)   就會出現Index   was   outside   the   bounds   of   the   array錯誤.
若我打開程式後.每個TabPage都點一遍後.就不會出錯.
不知道是不是.Net的Bug?大家有沒碰到過.

                ListBox   .DataSource   =   ds.Tables(0)
                ListBox   .DisplayMember   =   ds.Tables(0).Columns(1).ColumnName
                ListBox   .ValueMember   =   ds.Tables(0).Columns(0).ColumnName
              if   ListBox   .Items.Count   >   0   Then   ListBox   .SelectedIndex   =   0



------解决方案--------------------
ListBox.SelectedItems.Count> 0 但執行ListBox.SelectedIndex=0
SelectedIndex 与 SelectedItem 对应

------解决方案--------------------
检查你的变量
我用TabPage也遇到过相同的问题
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: