![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
|
День добрый. Подскажите пожалуйста по такому вопросу:
Работаю с Listview в режиме vsReport. Появилась необходимость ассоциировать список с иконками из ImageList. У себя для добавления списка в ListView использую код: Код:
for i := 1 to fileCount do begin
fileName := copy(fileClump,1,pos('`',fileClump)-1);
fileListView.AddItem(fileName,pointer(self));
fileListView.Update;
delete(fileClump,1,pos('`',fileClump));
end;Код:
fileCount - integer Код:
fileClump - string Вот в чем суть вопроса, нашла тут функцию: Код:
function IconNum(strExt: string): Integer; begin else if (strExt = '.txt') or (strExt = '.doc') then Result := 2 else if (strExt = '.exe') or (strExt = '.com') then Result := 3 else Result := 1; end; Как можно её мне применить? |
|
#2
|
|||
|
|||
|
как-то так
Код:
var Item:TListItem; Item:=fileListView.AddItem(fileName,pointer(self)); Iemm.ImageIndex := IconNum(ExtractFileExt(fileName)); И ещё может быть понадобится LowerCase |
| Этот пользователь сказал Спасибо icWasya за это полезное сообщение: | ||
Elza (26.02.2014)
| ||
|
#3
|
||||
|
||||
|
Да и функцию замените на
Код:
function IconNum(strExt: string): integer; begin Result:= 1; strExt:= ExtractFileExt(strExt); if (strExt = '.txt') or (strExt = '.doc') then Result:= 2; if (strExt = '.exe') or (strExt = '.com') then Result:= 3; end; ... Item.ImageIndex:= IconNum(fileName); ... |
|
#4
|
|||
|
|||
|
Хорошо, изменила и делаю
Код:
for i := 1 to fileCount do begin
fileName := copy(fileClump,1,pos('`',fileClump)-1);
Item:=fileListView.AddItem(fileName,pointer(self));
Item.ImageIndex := IconNum(LowerCase(ExtractFileExt(fileName)));Цитата:
|
|
#5
|
||||
|
||||
|
А вот так
Код:
{
The following example shows how to show all files and their
associated icons of a folder in a TListView.
To test the code, you need a ListView1 and a ImageList1 where the icons are stored.
}
uses ShellApi;
procedure LV_InsertFiles(strPath: string; ListView: TListView; ImageList: TImageList);
var
i: Integer;
Icon: TIcon;
SearchRec: TSearchRec;
ListItem: TListItem;
FileInfo: SHFILEINFO;
begin
// Create a temporary TIcon
Icon := TIcon.Create;
ListView.Items.BeginUpdate;
try
// search for the first file
i := FindFirst(strPath + '*.*', faAnyFile, SearchRec);
while i = 0 do
begin
with ListView do
begin
// On directories and volumes
if ((SearchRec.Attr and FaDirectory <> FaDirectory) and
(SearchRec.Attr and FaVolumeId <> FaVolumeID)) then
begin
ListItem := ListView.Items.Add;
//Get The DisplayName
SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
SizeOf(FileInfo), SHGFI_DISPLAYNAME);
Listitem.Caption := FileInfo.szDisplayName;
// Get The TypeName
SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
SizeOf(FileInfo), SHGFI_TYPENAME);
ListItem.SubItems.Add(FileInfo.szTypeName);
//Get The Icon That Represents The File
SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
SizeOf(FileInfo), SHGFI_ICON or SHGFI_SMALLICON);
icon.Handle := FileInfo.hIcon;
ListItem.ImageIndex := ImageList.AddIcon(Icon);
// Destroy the Icon
DestroyIcon(FileInfo.hIcon);
end;
end;
i := FindNext(SearchRec);
end;
finally
Icon.Free;
ListView.Items.EndUpdate;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// Assign a Imagelist to the ListView
ListView1.SmallImages := ImageList1;
// Show Listview in Report Style and add 2 Columns
ListView1.ViewStyle := vsReport;
ListView1.Columns.Add;
ListView1.Columns.Add;
LV_InsertFiles('C:\Windows\', ListView1, ImageList1);
end; |
|
#6
|
|||
|
|||
|
увы так не подходит=(
|
|
#7
|
||||
|
||||
|
Только сейчас дошло
Код:
... fileListView.AddItem(fileName, pointer(self)); fileListView.Items.Item[i].ImageIndex:= IconNum(fileName); ... |
| Этот пользователь сказал Спасибо Alegun за это полезное сообщение: | ||
Elza (26.02.2014)
| ||