如何让两个listbox同步选择??(问题还没有解决!!!!)(200分)

G

gf.z

Unregistered / Unconfirmed
GUEST, unregistred user!
问题:如何让两个listbox同步选择??? ( 积分:100, 回复:6, 阅读:24 )
分类:控件 - 使用 ( 版主:amo, cAkk )
来自:gf.z, 时间:2002-9-30 13:16:00, ID:1355419 | 编辑 [显示:小字体 | 大字体]
两个listbox,如何让两个listbox同步选择?如
listbox1选中第2项,则listbox2也自动选中第2项!!
如:
listbox1 listbox2
aaa bbb
dss dfd
eee eee2

当我选择‘eee'时候,listbox2自动选择’eee2‘???


------------------------
采用listbox2.itemindex:=listbox1.itemindex;
不能实现!
当点击listbox1的项目时候,listbox2的对应项目不会变成选中状态!!!
请教!!??

 
怎么会那?我这里都可以,测试通过,效果也正确啊:
procedure TForm1.ListBox1Click(Sender: TObject);
begin
ListBox2.ItemIndex := ListBox1.ItemIndex;
end;

procedure TForm1.ListBox2Click(Sender: TObject);
begin
ListBox1.ItemIndex := ListBox2.ItemIndex;
end;
 
我这里listbox2好象没什么反应一样!!!!!!!!!
就跟没有这句语句一样!!!
 
同意 beta 的!完全可以通过!!!
是不是你的这个物件有问题??
 
谢谢各位!!我在去试试!!
 
>>采用listbox2.itemindex:=listbox1.itemindex;不能实现!
怪了,怎么会不能实现呢?
除此方法我倒想不出别的办法了
 
我在DELPHI7也试过了,就是楼上各位说的:
ListBox2.ItemIndex := ListBox1.ItemIndex;
就可以了。是不是你的Delphi有问题,重新安装吧。

 
我在d5上试过可以的。
是不是你的delphi有问题啊
 
楼上的方法不错,可行。
如果楼上的方法行不同,那就用最笨的方法,麻烦一点
在listbox1的Onclick事件实现如下
procedure TForm1.ListBox1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to (listbox1.Count-1) do
if listbox1.Selected then
listbox2.Selected :=true;
end;
 
多人接受答案了。
 
顶部