//可以显示的用法
string abc = string.Format("下标:{0}, 选中:{1}", listBox1.SelectedIndex, listBox1.SelectedItem);
MessageBox.Show(abc);
//下面的为什么不能,我想直接点就取得选中的值
MessageBox.Show(listBox1.SelectedIndex,listBox1.SelectedItem);
我只想看一下弹出来看下正不正确。之前有试过.tostring,但是后面没有加上(),- - !
想最后确认下,listBox1.SelectedItem,这个直接就是int类型的吗?怎么知道它就是int类型呢?
listBox1.SelectedItem这个不是int型,而是object型。
当你在写listBox1.后,就可以看vs.net弹出的智能感知,看看这个SelectedItem是什么类型的。
还是不行哦,
刚试了,
//获取选中项可以这样写
MessageBox.Show(listBox1.Text);
选中下标就不知道怎么写了
难道非得写这么长才可以么?
//这个写法是可以的
MessageBox.Show(string.Format("{0}", listBox1.SelectedIndex));
MessageBox.Show(listBox1.SelectedIndex);
不用写那么长