Q&A

  • ListView에서 셀렉트할때....위치가 고정이 안됩니다...
lvwFileList.ItemIndex := intTemp;
lvwFileList.SetFocus;

이렇게 하면은 선택은 되는데....막상 업,다운방향키로 움직이면 맨처음 아이템에서부터 다시 시작합니다..분명히 중간쯤 선택됐는데...막상 방향키로는 제대로 작동을 하지 않네요...어찌하면 좋을까요...쩝....

함수전체...
//디렉토리와 화일출력
procedure GetDirectories(lvwFileList: TListView; Directory: string);
var
  SearchRec: TSearchRec;
  Item: TListItem;
  ftC: TSystemTime;
  intPoint, intIndex,intTemp: Integer;
  strTemp: WideString;
  blnUpDir: Boolean;

begin
  blnUpDir := False;
  Screen.Cursor := crHourGlass;
  lvwFileList.Items.BeginUpdate;
  lvwFileList.Items.Clear;

//디렉토리출력
  if (Directory[length(Directory)] = '.') and (Directory[length(Directory)-1] = '.') then
  begin
    blnUpDir := True;
    strTemp := GetUpDir(Directory);
  end;

  if Directory[length(Directory)] <> '' then Directory := Directory + '';
  if FindFirst(Directory + '*.*', faDirectory, SearchRec) = 0 then
  begin
    repeat
      if ((SearchRec.Attr and faDirectory) = faDirectory) and (length(SearchRec.Name) > 1) then // <> '.') then
      begin
        if (SearchRec.Attr and faDirectory > 0 ) then
        begin
          Item := lvwFileList.Items.Add;
          if SearchRec.Name[1] <> '.' then
            Item.ImageIndex := 0
          else
            Item.ImageIndex := 1;
          Item.Caption := '[' + SearchRec.Name + ']';
          Item.SubItems.Add('');
          Item.SubItems.Add('<Dir>');
          FileTimeToSystemTime(SearchRec.FindData.ftCreationTime, ftC);
          with ftC do
            Item.SubItems.Add(format('%0.2d/%0.2d/%0.4d %0.2d:%0.2d:%0.2d', [ wDay,wMonth,wYear,wHour,wMinute,wSecond]));
        end;
      end;
    until FindNext(SearchRec) <> 0;
  end;

//화일출력
  if FindFirst(Directory + '*.*', CONFILEATTRIB , SearchRec) = 0 then
  begin
    repeat
      if SearchRec.Name[1] <> '.' then
      begin
        Item := lvwFileList.Items.Add;
        Item.ImageIndex := 2;
        intPoint := pos('.',SearchRec.Name);
        if intPoint > 0 then
        begin
          intPoint := length(SearchRec.Name);
          repeat
            if SearchRec.Name[intPoint] = '.' then break;
            intPoint := intPoint -1;
          until intPoint > 0;
          if intPoint > 0 then
          begin
            Item.Caption := copy(SearchRec.Name,1,intPoint-3);
            Item.SubItems.Add(copy(SearchRec.Name,IntPoint-1,length(SearchRec.Name)));
          end
          else
          begin
            Item.Caption := SearchRec.Name;
            Item.SubItems.Add('');
          end;
        end
        else
        begin
          Item.Caption := SearchRec.Name;
          Item.SubItems.Add('');
        end;
        Item.SubItems.Add(FormatFloat('#,##0', (SearchRec.Size)));
        FileTimeToSystemTime(SearchRec.FindData.ftCreationTime, ftC);
        with ftC do
          Item.SubItems.Add(format('%0.2d/%0.2d/%0.4d %0.2d:%0.2d:%0.2d', [ wDay,wMonth,wYear,wHour,wMinute,wSecond]));
      end;
    until FindNext(SearchRec) <> 0;
  end;
  FindClose(SearchRec);
  lvwFileList.Items.EndUpdate;

  intTemp := 0;
  if blnUpDir  = True then
  begin
    for intIndex := 0 to lvwFileList.Items.Count-1 do
    begin
      if strTemp = lvwfilelist.Items.Item[intIndex].Caption then
      begin
        intTemp := intIndex;
        break;
      end
    end
  end;

  lvwFileList.ItemIndex := intTemp;
//  Item := lvwFileList.Items[inttemp];
//  Item.Selected := true;
  lvwFileList.SetFocus;
  Screen.Cursor := crDefault;
end;
0  COMMENTS