?
Solved

Customize TListView

Posted on 2003-03-05
6
Medium Priority
?
358 Views
Last Modified: 2010-04-04
Hi,

I use a TListView component to display some data (report style). How can I add the ability to customize it? I want the user to be able to rearrange columns and hide some others. Are there built in features of TListView or do I have to add them myself?



Regards
J
0
Comment
Question by:j42
[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
6 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 8072003
Hi,

You can use OnColumnClick or OnColumnRightClick to hide a column. Example: when a user right-clicks on a certain column then it gets hidden (it can be restored later by resizing it either in code or manually):

procedure TForm1.ListView1ColumnRightClick(Sender: TObject;
  Column: TListColumn; Point: TPoint);
begin
  Column.Width := 0;
end;

Regards, Geo
0
 
LVL 2

Expert Comment

by:steve_hsk
ID: 8072678
Hi J ...

I'll keep it a lil shorter this time :-)

Depends on exactly what you trying to do. If you want to change the appearance of a particular item, column, or draw the whole view yourself to provide graphics and a complete custom look, then you can use these events :

OnDrawItem
-----
OnCustomDraw
OnCustomDrawItem
OnCustomDrawSubItem
-----
OnAdvancedCustomDraw
OnAdvancedCustomDrawItem
OnAdvancedCustomDrawSubItem

to draw on : listview1.Canvas ... DrawRect, FillRect, etc

(if you need examples [they are lengthy], let me know)

If you just want to be able to hide and show columns then as Geobul suggested, you can choose an appropriate event, and set the column.width = new_value appropriately.

Steve
0
 
LVL 2

Author Comment

by:j42
ID: 8074458
Hi Steve,
nice to hear from you. Did you read the posting of swift99 in my last question. I guess I annoyed him in some way...
> (if you need examples [they are lengthy], let me know)
Thanks for offering. I know how to do it myself, I just want to avoid reinventing the wheel.

Best of luck
J
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:steve_hsk
ID: 8074992
Hi J,

I'm not so sure you annoyed anyone ... everyone has a bad day from time to time ;-)

Speak to ya soon,
Steve
0
 
LVL 2

Author Comment

by:j42
ID: 8081562
Hi,

I am going to answer the question myself. However thanks for beeing helpful. I will split the points.
Points for geobul:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20541229.html
Points for Steve:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20541230.html


// Switch two columns
procedure TForm1.Button2Click(Sender: TObject);
const
  SOURCE = 2;
  DEST = 1;
begin
  ListView1.Columns[DEST].Index := SOURCE;
  ListView1.UpdateItems(0, ListView1.Items.Count - 1);
end;

// Remove column
procedure TForm1.Button3Click(Sender: TObject);
var
  i: integer;
const
  COL = 3;
begin
  ListView1.Columns[COL].Destroy;

  for i := 0 to (ListView1.Items.Count - 1) do
  begin
    ListView1.Items[i].SubItems.Delete(COL - 1);
  end;
end;



Regards
J
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8081826
PAQ'd and points refunded

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
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 …
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

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