现在我做的一个程序,要求是用ListView显示数据表记录,这是很容易就实现了,但是需要根据时间字段来进行导航,比如在ListBox里存的是时间字符串如'2004-10-17 11:10:10',如何用这个值在ListView里找到该记录,因为要让ListView联动啊,显示给用户的效果就跟DBGrid移动到匹配的记录一样

解决方案 »

  1.   

    procedure TfrmMain.LBSysClick(Sender: TObject);
    var
        I, J:Integer;
        Str:String;begin
         for I:=0 to LBSys.Items.Count-1 do
         begin
              if LBSys.Selected[I] then
                 Str:=Trim(LBSys.Items[I]);
         end;//     LVSys.FindCaption(0, Str, True, True, True);     for I:=0 to LVSys.Items.Count-1 do
         begin
              for J:=0 to LVSys.Items[I].SubItems.Count-1 do
              begin
                   if LVSys.Items[I].SubItems[J]=Str then
                   begin                     SysEndPos:=I;                     LVSys.Scroll(0, (SysEndPos-SysStartPos)*13);{
                         if EndPos>StartPos then
                         begin
                              if EndPos-StartPos>LVSys.VisibleRowCount then
                                 LVSys.Scroll(0, (EndPos-StartPos)*13);
                         end
                         else
                         if StartPos>EndPos then
                         begin
                              if StartPos-EndPos>LVSys.VisibleRowCount then
                                 LVSys.Scroll(0, (EndPos-StartPos)*13);
                         end;
    }                    LVSys.Selected:=LVSys.Items[I];
                        LVSys.SetFocus;
                        SysStartPos:=SysEndPos;                    break;
                   end;
              end;
         end;end;