Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How does one implement a progressbar in listview

Posted on 2001-08-14
8
Medium Priority
?
538 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 116 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

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

972 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