Solved

Populate ListView (report) based on column caption

Posted on 2004-09-17
3
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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