Solved

Populate ListView (report) based on column caption

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

16 Experts available now in Live!

Get 1:1 Help Now