Board index » delphi » Adding a gauge to Listview::subItem at runtime?

Adding a gauge to Listview::subItem at runtime?

Hi all,

I'm not too clear on how I'd go about doing this so thought to seek some
advice.

I have a ListView. I get all logical drives at run time and add them to the
listview caption, easy enough.
Now I also get the free, and total disk space for each drive.

Question: How do I create and add a gauge control that can be used in the
subitem for each of the ListViews items?

Make sense?

Any help or tips would be much appreciated as I've not created any transient
objects at run time before.

Thanks, Aaron.

 

Re:Adding a gauge to Listview::subItem at runtime?


"Aaron" <a.mor...@NOSPAMparadise.net.nz> wrote in
news:oe%f9.1513$b5.134626@news02.tsnz.net:

Quote
> Hi all,

> I'm not too clear on how I'd go about doing this so thought to seek
> some advice.

> I have a ListView. I get all logical drives at run time and add them
> to the listview caption, easy enough.
> Now I also get the free, and total disk space for each drive.

> Question: How do I create and add a gauge control that can be used in
> the subitem for each of the ListViews items?

> Make sense?

> Any help or tips would be much appreciated as I've not created any
> transient objects at run time before.

> Thanks, Aaron.

I have not added gauge to a listbox, but I have added bitmaps.

You could prepare a bitmap that shows the current usage
at startup. Then you could add the bitmap to the ListView.
The downside would be that it would not update according to changes
made to the disk space, unless you recreated the bitmap and reloaded it.

ex.

begin
  ListView := TListView.Create(Self);
  ListView.Width := 50;
  ListView.Height := 50;

  For i := 0 to High(Drives) do
  begin
    MyBit[i] := TBitMap.Create;
    MyBit[i].Width := 50;
    MyBit[i].Height := 50;

    //draw bitmap
    ImageLIst1.Add(MyBit[i],nil);
  end;

  with ListView do
  begin
    SmallImages := ImageList1;
    LargeImages := ImageList1;

    Parent := Self;
    Align := alClient;
    ViewStyle := vsIcon;

    for I := 0 to High(Drives) do
    begin
      ListItem := Items.Add;
      ListItem.ImageIndex := I; //Here is where the gauge would be added
      ListItem.Caption := Drives[I];
    end;
  end;
end;

Re:Adding a gauge to Listview::subItem at runtime?


Ok. I thought about it some more. Her is the code that would do it.

procedure TForm1.FormCreate(Sender: TObject);
 const
  Names: array[0..5, 0..1] of ShortString = (
    ('Rubble', 'Barney'),
    ('Michael', 'Johnson'),
    ('Bunny', 'Bugs'),
    ('Silver', 'HiHo'),
    ('Simpson', 'Bart'),
    ('Squirrel', 'Rockey')
    );

var
  I: integer;
  NewColumn: TListColumn;
  ListItem: TListItem;
  ListView: TListView;
  MyBit: array [0..6] of TBitMap;
begin
  show;
  update;
  ListView := TListView.Create(Self);
  ImageList1.Width := Gauge1.Width;
  ImageList1.Height := Gauge1.Height;
  For i := 0 to 5 do
  begin
    MyBit[i] := TBitMap.Create;
    MyBit[i].Width := Gauge1.Width;
    MyBit[i].Height := Gauge1.Height;

    MyBit[i].Canvas.CopyRect(Rect(0,0, MyBit[i].Width,MyBit[i].Height),
                             Form1.Canvas,
                             Rect(Gauge1.Left, Gauge1.Top,
                                  Gauge1.Left + Gauge1.Width,
                                  Gauge1.Top  + Gauge1.Height) );

    ImageLIst1.Add(MyBit[i],MyBit[i]);
  end;

  with ListView do
  begin
    SmallImages := ImageList1;
    LargeImages := ImageList1;

    NewColumn := Columns.Add;
    NewColumn.Caption := 'Drives';

    Parent := Self;
    Align := alClient;
    ViewStyle := vsLIst;

    for I := 0 to High(Names) do
    begin
      ListItem := Items.Add;
      ListItem.ImageIndex := I;
      ListItem.Caption := Names[I][0];
    end;
  end;
end;

Re:Adding a gauge to Listview::subItem at runtime?


Hi,

you don't need create a gauge for every item in this column. You must use
custom drawing and draw an image "like" gauge.

--
With best regards, Mike Shkolnik
E-mail: mshkol...@scalabium.com
WEB: http://www.scalabium.com

Quote
Aaron <a.mor...@NOSPAMparadise.net.nz> wrote in message

news:oe%f9.1513$b5.134626@news02.tsnz.net...
Quote
> Hi all,

> I'm not too clear on how I'd go about doing this so thought to seek some
> advice.

> I have a ListView. I get all logical drives at run time and add them to
the
> listview caption, easy enough.
> Now I also get the free, and total disk space for each drive.

> Question: How do I create and add a gauge control that can be used in the
> subitem for each of the ListViews items?

> Make sense?

> Any help or tips would be much appreciated as I've not created any
transient
> objects at run time before.

> Thanks, Aaron.

Re:Adding a gauge to Listview::subItem at runtime?


Excellen works a treat, thank you.

Aaron.

Other Threads