搞死的啦。怎样使一个Caption为“XX”的Listview选中啊。(50分)

  • 主题发起人 主题发起人 huait
  • 开始时间 开始时间
H

huait

Unregistered / Unconfirmed
GUEST, unregistred user!
比如:
Listview中有好多数据
第一列 第二列 第三列
a aa aaa
b bb bbb
c cc ccc

怎样通过程序选中第一列为"b"的一行,高手请帮我
 
for i:=0 to ListView.Items.Count-1 do
begin
if ListView.Items.Caption:='b' then
ListView.Items.Selected:=True;
Break;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
I :Integer;
begin
for I :=0 to ListView1.Items.Count-1 do
begin
if ListView1.Items.Caption='b' then
ListView1.Items.DropTarget :=True;
end;
end;
 
试了,还是不行,可能是属性设置不对吧,高手请指点!!
 
for I :=0 to ListView1.Items.Count-1 do
begin
if ListView1.Items.Caption='b' then
ListView1.Items.Selected :=True;
end;
ListView1.SetFocus; //the point
 
切!真够笨的!

var item:tlistitem;
item:=listview1.FindCaption(0,'b',true,false,false);
if item<>nil then listview1.selected = item;
 
to:一个过客
兄弟,你的方法还不错,但你漏掉了
ListView1.SetFocus;
这一句没有的话,就看不到结果了。
 
有时候不一定要Setfocus的。
此时可以这样子写:
var item:tlistitem;
item:=listview1.FindCaption(0,'b',true,false,false);
if item<>nil then begin
item.focused:=true;
item.selected:=true;
item.makevisible(true);
postmessage(listview1.handle, wm_setfocus, 0, 0);
end;

这种写法的效果就是把查到的那条记录高亮度显示出来。
 
试试我的代码,我的应用里面就是这么实现的!
listview1.Items.Selected := true;
listview1.Items.MakeVisible(true);  //很重要!!
 
后退
顶部