?
Solved

Populate ListView (report) based on column caption

Posted on 2004-09-17
3
Medium Priority
?
418 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 500 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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