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

ListBox.Items.Count>0 但執行ListBox.SelectedIndex=0 時確出錯.Index was outside the bounds of the array
http://community.****.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也遇到过相同的问题