procedure TRichList.Search; var s: string; i: integer; p: TPoint; begin if LV.Items.Count=0 then exit; if CanSearch(s,FDlgCol) then begin for i:=0 to Lv.Items.Count-1 do begin if Lv.Items[i].Caption = s then begin LV.SetFocus; lv.Selected:= lv.Items[i]; lv.Items[i].Focused:= true; p:=lv.Items[i].Position; lv.Scroll(0,p.y-20); lv.Scroll(p.x-20,0); exit; end; end; //lv.FindCaption(0,s,false,true,true); application.MessageBox('搜索结束,没有找到符合条件的人','提示',MB_OK+MB_ICONINFORMATION); lv.Selected:= lv.Items[0]; end; end; 其中lv就是listview
var s: string;
i: integer;
p: TPoint;
begin
if LV.Items.Count=0 then exit;
if CanSearch(s,FDlgCol) then
begin
for i:=0 to Lv.Items.Count-1 do
begin
if Lv.Items[i].Caption = s then
begin
LV.SetFocus;
lv.Selected:= lv.Items[i];
lv.Items[i].Focused:= true;
p:=lv.Items[i].Position;
lv.Scroll(0,p.y-20);
lv.Scroll(p.x-20,0);
exit;
end;
end;
//lv.FindCaption(0,s,false,true,true);
application.MessageBox('搜索结束,没有找到符合条件的人','提示',MB_OK+MB_ICONINFORMATION);
lv.Selected:= lv.Items[0];
end;
end;
其中lv就是listview
ListView1.Items[i].MakeVisible(True);
var
DX,DY : integer;
begin
DX := lvPlugIns.Selected.Position.X - lvPlugins.Left;
DY := lvPlugIns.Selected.Position.Y - lvPlugins.top;
lvPlugIns.Scroll(DX,DY);
end;
自己照这个方法算一算就可以了.
就是先用,sendMessage,ListViewHwnd,LVM_GETTOPINDEX,0
得到当前的最上面的那个item的index,然后与找到的那个index,下的内容全部交换一下。如果不容许交换顺序
那么就用,sendMessage,ListViewHwnd,LVM_SCROLL,0,dy
至于dy = ?,就要自己算了,
LVM_SCROLL = LVM_FIRST + 20
直接带常数 0x1000+20
var
tmpItem: TListItem;
dx,dy: integer;
begin
tmpItem := listview1.FindCaption(0,edit1.Text,true,false,true);
listview1.Selected := tmpItem;
listview1.SetFocus;
dx := tmpItem.Position.X - listview1.Left;
dy := tmpItem.Position.Y - listview1.Top - 20;
listview1.Scroll(dx,dy);
end;
我试过了,完全可以的。
还有,我使用listview1.scroll就是不行!