紧急问题!如何判断ListBox里的任意一项被选中?!!(20分)

A

asdqwe

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要在选择了ListBox里的任意一项后执行某操作,请问如何判断选中了ListBox里的任意一项内容?
代码该加在什么地方?
 
listbox.items.checked
 
showmessage(listbox1.Items.Strings[listbox1.ItemIndex]);
(必须考虑到listbox1.itemsindex=-1)
 
能具体点吗?
代码写在什么位置?
i要如何定义,是一个循环吗?
 
for i:=0 to ;listbox.items,count-1do
 
是在ListBox的OnClick事件里加吗?
 
随便你写在哪,搞个button click 事件 就行啊
或者listbox 的 change事件中
for i:=0 to listbox1.itemcount -1do
showmessage(listbox1.Items.Strings[listbox1.ItemIndex]);
 
listbox没有change事件啊?
 
var
i:integer;
begin
for i:=0 to listbox1.count -1do
if listbox1.item.check:=true then
........
end;
 
编译时这句过不去 ?
if ListBox1.Items.checked then
 

建议先学学delphi里的数据类型。
ListBox1.Items是什么类型呢?
ListBox1.ItemIndex是选择的那项序号。
在listBox的OnClick事件中
procedure TForm1.ListBox1Click(Sender: TObject);
begin
showmessage(listbox1.Items.Strings[listbox1.itemindex]);
end;
 
OnClick事件里应该可以吧
 
单击事件中
Label1.Caption:=ListBox1.ItemIndex;
 
不明白,现在只是这句过不去。
var
i:integer;
begin
for i:=0 to listbox1.count -1do
if ListBox1.Items.checked then
//这句编不过去,怎么处理?
........
end;
 
不明白,现在只是这句过不去。
var
i:integer;
begin
for i:=0 to listbox1.count -1do
//其实是这一句错了,应该为for i:=0 to listbox1.items.count -1do

if ListBox1.Items.checked then
//这句编不过去,怎么处理?
........
end;
 
其实你在ListBox的OnClick事件里写就可以呀
当前被选中的项的序号是ListBox1.ItemIndex,看清楚不要写错了
然后有ListBox1.Items.Strings[]等等的方法让你去调用,很简单的
好好琢磨一下吧
 

唉,看看Items的类型你就不会这样问了。
如果你一定要用这种方法,ListBox还有另一个属性的:Selected
这个属性应该是你要的了。
 
接受答案了.
 
listbox1.itemindex表示被选种的项
 
顶部