首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

ListBox.Items.Count>0 但執行ListBox.SelectedIndex=0 時確出錯.Index was outside the b

2012-01-28 
ListBox.Items.Count0 但執行ListBox.SelectedIndex0 時確出錯.Index was outside the bounds of the ar

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也遇到过相同的问题

热点排行