Dynamic listView

I'd like to create the items in the listView dynamically, and also its images. The image consists of a line with different colours. What is the easiest way to do it? And I also need to clear the list, which call i need to use to perform the clearing?
maulingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KECommented:
To clear the list set Items.Count := 0;

I don't understand what you mean exactly with the image part...
To set the image on the item, use Item.ImageIndex - and for the subitems use SubImageIndex[x];

BTW. Remember to Connect an ImageList to your ListView;

The only thing you need to dynamically drive the imagelist is Items.Count and the OnItemData event. The OnItemData event should apply the Item and SubItems data values (I'm not refering to Item.Data) with reference to the Item.Index.

Regards

0
men xinCEOCommented:
mauling:

I have a simple example for you.There are a Button ,a listview and a imagelist in a form.There are sevrial icons in the imagelist.You can set the listview's largeimage or smallimage link to the imagelist(by your listview's style).
And the codes is:


procedure TForm1.ListView1GetSubItemImage(Sender: TObject; Item: TListItem;
  SubItem: Integer; var ImageIndex: Integer);
//this function can draw listview's subitemimage.
begin
  if SubItem<>2 then
    ImageIndex:=SubItem
  else
    ImageIndex:=-1;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i,j:Integer;
begin
  with ListView1 do begin
    Items.Clear;
    for j:=1 to 5  do begin
      Items.Add;
      Items[j-1].Caption:=format('item%d',[j]);
      For i:=1 to 4 do begin
        if i<3 then
          Items.Item[j-1].SubItems.Add('') //subitem 1&2 put ''
        else
          Items.Item[j-1].SubItems.Add(Format('%d,%d',[j,i]))
      end;
    end;
  end;
end;


menxin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MadshiCommented:
mauling, sounds like a task for the virtual TListView mode. This mode is available in Delphi4 or Delphi5. If you only have D2 or D3, download the TExtListView component from this page:

http://www.delphifreestuff.com/

If you've D4 or D5, look at the "c:\delphi\demos\virtual listview" demo.

Does this help?

Regards, Madshi.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

men xinCEOCommented:
I use Delphi5
0
maulingAuthor Commented:
Thanks, Menxin.
0
KECommented:
Oh, I just realized that "dynamically" also has another meaning ;-)

Anyway, if you wan't it to be "driven dynamically", or let's call it "as a virtual list", then follow my directions - otherwise I believe that menxin has answered you question.

Regards
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.