Solved

Populate ListView (report) based on column caption

Posted on 2004-09-17
3
371 Views
Last Modified: 2010-04-04
I've struggled with this for a few days...

basically i had a LOT of code to do one simple task.

populate a listview (report mode) based on what view the user is in.

i.e...

column[0].caption may = 'First Name' or it may = 'Last Name'

so if column[0] = 'Last Name' i want the last name to go there then continue down the columns adding subitems.

i'm sure there is a simple way to do this, but i haven't quite figured it out. any help?
0
Comment
Question by:gwarguitar
3 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 12087795
0
 
LVL 3

Expert Comment

by:dlengel
ID: 12089701
I used to move columns that way until I found Mike Lischke's VirtualTreeView.  The VirtualTreeView paradigm is completely different than TListView, so it's hard to learn, but it supports everything I have ever wanted it to do with no hacks or workarounds or inefficient updating code.  It also does some amazing things that TListView can't do at all.  

For more information, please see http://www.delphi-gems.com/VirtualTreeview/VT.php
0
 
LVL 10

Accepted Solution

by:
Jacco earned 125 total points
ID: 12090677
Here is a bit of code:

procedure TForm1.Button1Click(Sender: TObject);
var
  liColumn: Integer;
  lField: TField;
begin
  ListView1.Items.BeginUpdate;
  try
    with Table1 do
    begin
      First;
      while not EOF do
      begin
        with ListView1.Items.Add do
          for liColumn := 0 to ListView1.Columns.Count-1 do
          begin
            lField := Table1.FindField(ListView1.Columns[liColumn].Caption);
            if Assigned(lField) then
              if liColumn > 0 then
                SubItems.Add(lField.AsString)
              else
                Caption := lField.AsString;
          end;
        Next;
      end;
    end;
  finally
    ListView1.Items.EndUpdate;
  end;
end;

I tested it with DBDEMOS.CUSTOMER and a list view with two column City and Company.

Regards Jacco
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now