Solved

How does one implement a progressbar in listview

Posted on 2001-08-14
8
467 Views
Last Modified: 2010-04-06
Hello there

Im wanting to put in a progressbar inside a listview. The progress bars will be in certain rows aligned to a certain column, for example Napster or Aimster.

How is it done, anyone know?

I believe it was the CustomDraw method but I didnt know how it works.

Ben Iti
0
Comment
Question by:Ben_iti
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Expert Comment

by:fva
ID: 6383673
On D3's version of TListView there is no CustomDraw method or property, so I cannot help with that (i.e. if your version has one). However, the principle is the following (Win API-level):

Whenever drawing is do be done on the list-view component Windows posts a notify message to the owner of the list-view (normally your form) saying "I am going to draw the list-view. Do you want to do anything special?". If you respond with "Yes" the API-way then Windows will keep on notifying you about each phase of the draw process and you will have the chance to do your own painting and that includes drawing the progress bar where required.

The whole process iss rather complicated and probably you are far better off if the version of Delphi you are using _has_ that CustomDraw property. However, as I said (sorry), you will probably get help on that from someone with a newer version of Delphi.

F.
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6385045
So, why you cannot just place ProgressBar (I prefer Gauge) control on listview. All you need it set the Parent property and set the control position.

Regards.
0
 

Author Comment

by:Ben_iti
ID: 6403197
Yeah hi Slavak

What do you mean by set control position. How do I do that?
So far its working, its there but in the wrong position.
Please reply

Ben Iti
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Expert Comment

by:Slavak
ID: 6403360
try override OnCustomDrawSubItem event like this:


procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
Var
 R   : TRect;
 I   : Integer;
 P   : Integer;
begin
 If (SubItem <> 1) Then Exit;  // check for right column

 DefaultDraw := False;

 R := Item.DisplayRect(drBounds);

 For I := 0 To SubItem - 1 Do
  R.Left := R.Left + ListView1.Columns[I].Width;

 R.Right := R.Left + ListView1.Columns[SubItem].Width;
 R := Rect(R.Left + 1, R.Top + 1, R.Right - 1, R.Bottom - 1);

 ListView1.Canvas.Brush.Color := clBlack;
 ListView1.Canvas.FrameRect(R);

 P := Random(100);  // set gauge position here

 R.Right := R.Left + (ListView1.Columns[SubItem].Width * P) div 100;
 R := Rect(R.Left + 1, R.Top + 1, R.Right - 1, R.Bottom - 1);

 ListView1.Canvas.Brush.Color := Random($FFFFFF);
 ListView1.Canvas.FillRect(R);
 ListView1.Canvas.Brush.Color := ListView1.Color;
End;
0
 
LVL 4

Accepted Solution

by:
DMN earned 29 total points
ID: 6404269
Here is MY answer from PAQ's:
================================


Here is a few steps to make your wish to be true.

1. Make new project. Place TListView on the form.
2. Double click your ListView and add some items and subitems to it. Each item should have one subitem,
contains integer per-cent value.

Item: Item1
SubItem: 20

Item: Item2
SubItem: 80

Item: Item3
SubItem: 50

3. Close items editor, rightclick listview, start columns editor. Add 2 (two) columns.

4. Set ViewStyle of your listview to vsReport.

5. DO NOT set OwnerDraw property to TRUE. Leave it false, otherwise yor OnCustomDrawSubItem will never
start...

6. Add next handler to OnCustomDrawSubItem:

procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
 Item: TListItem; SubItem: Integer; State: TCustomDrawState;
 var DefaultDraw: Boolean);
var
 v,w,i:integer;
 Rect,Rect2:TRect;
begin
 if (SubItem=1) then
   begin
     DefaultDraw:=False;
     w:=Sender.Column[SubItem].Width;
     v:=StrToInt(Item.Subitems[SubItem-1]);
     Rect:=Item.DisplayRect(drBounds);
     for i:=0 to SubItem-1 do
       Rect.Left := Rect.Left+Sender.Column[i].Width;
     Rect2:=Rect;
     Rect2.Right := Rect2.Left+w;
     Rect.Right := Rect.Left+v*w div 100;
     with Sender.Canvas do
       begin
         Brush.Color:=clRed;
         Brush.Style:=bsSolid;
         FillRect(Rect);
         Brush.Color:=clBlack;
         FrameRect(Rect2);
       end;
   end;
end;

7. Enjoy!!!!!!!!!!!!!!!!!!!!!!!!!!!



0
 
LVL 3

Expert Comment

by:Slavak
ID: 6405292
Good, DMN. But what a difference?

0
 
LVL 4

Expert Comment

by:DMN
ID: 6405453
Oops - sorry
0
 

Author Comment

by:Ben_iti
ID: 6891991
Thanks both of you's
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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