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