Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create a TProgressBar inside a TListView Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
28-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
52
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I would like to display a progress bar as a sub item in a TListView (vsReport 
mode). How can I do that?

Answer:

Well, you can in fact parent a live progressbar to a listview, you just have to do 
it at run-time. The sample below has timer that randomly steps the progress bars. 
The bar is added to the last column of the listview.

There are some gotchas here: the DisplayRect method of a listitem does not return 
the correct position unless the control is visible, thus the hack used at the top 
of the method to ensure this. And of course you will have to adjust the width and 
left bound of the progress bars if the user resizes columns. And you need to add 
new bars if the user can add items and destroy bars if the user can delete item.

1   procedure TForm1.FormCreate(Sender: TObject);
2   var
3     pb: TProgressBar;
4     r: TRect;
5     i, k: Integer;
6   begin
7     Show;
8     Application.ProcessMessages;
9     for i := 0 to listview1.items.count - 1 do
10    begin
11      r := listview1.items[i].DisplayRect(drBounds);
12      {last column is to take progress bar}
13      for k := 1 to listview1.columns.Count - 1 do
14        r.left := r.left + listview1.columns[k - 1].Width;
15      r.right := r.Left + listview1.columns[listview1.columns.Count - 1].Width;
16      pb := TProgressBar.Create(self);
17      pb.Parent := listview1;
18      pb.BoundsRect := r;
19      listview1.items[i].Data := pb;
20    end;
21  end;
22  
23  procedure TForm1.Timer1Timer(Sender: TObject);
24  var
25    i: Integer;
26    pb: TProgressbar;
27  begin
28    i := Random(listview1.items.count);
29    pb := TProgressBar(listview1.Items[i].Data);
30    if assigned(pb) then
31      if pb.Position = pb.Max then
32        pb.Position := 0
33      else
34        pb.StepBy(pb.Max div 10);
35  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC