Solved

Populate ListView (report) based on column caption

Posted on 2004-09-17
3
386 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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