Solved

How does one implement a progressbar in listview

Posted on 2001-08-14
8
495 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
[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
  • 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
Industry Leaders: 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 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

[Webinar] 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

734 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