我就是要LISTBOX中的内容随着指针的移动而使对应的项选中显亮。代码是:
procedure Tspwhform.Button7Click(Sender: TObject);
query1.First;
a:=ListBox1.Items.IndexOf(query1.FieldValues['ssspdl']);
if a<>-1 then ListBox1.Selected[a]:=true;
b:=ListBox2.Items.IndexOf(query1.FieldValues['ssspxl']);
if b<>-1 then ListBox2.Selected[b]:=true;procedure Tspwhform.Button8Click(Sender: TObject);
query1.Prior;
a:=ListBox1.Items.IndexOf(query1.FieldValues['ssspdl']);
if a<>-1 then ListBox1.Selected[a]:=true;
b:=ListBox2.Items.IndexOf(query1.FieldValues['ssspxl']);
if b<>-1 then ListBox2.Selected[b]:=true;procedure Tspwhform.Button9Click(Sender: TObject);
query1.next:
......
....程序大概就是这样了
现在的问题是每次就是LISTBOX1里的东西可以正确随着指针的移动而移动。LISTBOX2却只是在指针指象第一条时正确显示,然后就再也不随着指针而动了,怎么回事?救命啊
procedure Tspwhform.Button7Click(Sender: TObject);
query1.First;
a:=ListBox1.Items.IndexOf(query1.FieldValues['ssspdl']);
if a<>-1 then ListBox1.Selected[a]:=true;
b:=ListBox2.Items.IndexOf(query1.FieldValues['ssspxl']);
if b<>-1 then ListBox2.Selected[b]:=true;procedure Tspwhform.Button8Click(Sender: TObject);
query1.Prior;
a:=ListBox1.Items.IndexOf(query1.FieldValues['ssspdl']);
if a<>-1 then ListBox1.Selected[a]:=true;
b:=ListBox2.Items.IndexOf(query1.FieldValues['ssspxl']);
if b<>-1 then ListBox2.Selected[b]:=true;procedure Tspwhform.Button9Click(Sender: TObject);
query1.next:
......
....程序大概就是这样了
现在的问题是每次就是LISTBOX1里的东西可以正确随着指针的移动而移动。LISTBOX2却只是在指针指象第一条时正确显示,然后就再也不随着指针而动了,怎么回事?救命啊
该值为-1说明没有找到对应的值啊。仔细检查一下。
建议:
b:=ListBox2.Items.IndexOf(trim(query1.FieldByName('ssspxl').asString));因为用FieldValues取出来的数据可能是NULL
另外,要注意大小写的问题。
多谢zfmich()捧场,分全给你,不多,但还请笑纳了