ListView_Insertitem Help?

just write whatever you want
Post Reply
Armagedon
Posts: 14
Joined: Tue May 27, 2008 4:30 am

ListView_Insertitem Help?

Post by Armagedon »

can you give me a example for insert item to Listview with ListView_InsertItem in delphi?
thanks :oops:
iconic
Site Admin
Posts: 1064
Joined: Wed Jun 08, 2005 5:08 am

Code

Post by iconic »

Code: Select all

function InsertLvItem(const hLv: DWORD; lpText: PChar; dwIndex: DWORD): BOOL;
var
 lvi: ^LV_ITEM;
const
 dwSz = sizeof(lvi^);
begin
 lvi := VirtualAlloc(nil, dwSz, MEM_COMMIT, PAGE_READWRITE);
 lvi^.mask := LVIF_TEXT;
 lvi^.pszText := lpText;
 lvi^.iSubItem := 0;
 lvi^.iItem := dwIndex;
 result := ListView_InsertItem(hLv, lvi^) <> -1;
 VirtualFree(lvi, 0, MEM_RELEASE);
end;

You can't insert subitems with the macro ListView_InsertItem but this works correctly for captions.

Example:

Code: Select all

if InsertLvItem(Lv.Handle, 'Item 1', 0) then 
MessageBox(0,  'Item Inserted Successfully', 
                  'Information', (MB_OK or MB_ICONINFORMATION or MB_TOPMOST or MB_SETFOREGROUND));
--Iconic
Post Reply