Very urgent DBGrid draw

I need to show progressBars in a DBGrid on a certain column. So every record will show on column 7 a progressbar.
I tryed something but obviously did not work, because I did try to place the same ProgressBar in all the cells of the column... and I got a flashing column... the progressbar was moving in every cell ondraw.
So I need (only for showing) to have on that column to have progressbars.
I tryed to create the progressbars on each celldraw but I get an error. I am really in a rush here and I seem to be lost in this problem, considering the short time.
   I would probabely sort it myself in a few days but I do not have that long.
So please help !!!
I only have 475 points left so I will grade this question with a A grade and 400 points.
Here comes my code:
LVL 3
GhitzaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
calinutzConnect With a Mentor Commented:
Try this, tested:

var
  Form1: TForm1;
  LST:TList;
  i:integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
LST := TList.Create;
i:=0;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
i:=1;
end;

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
var
 rb : TProgressBar;
begin
If field.DisplayName='zile' then
begin
  rb := TProgressBar.Create(Self);
  rb.Name := 'pr' + inttostr(i);
  rb.Parent:=self;
  rb.Visible:=false;
  rb.Smooth:=true;
  rb.Position:=dataSource1.DataSet.FieldValues['Round'];
  Lst.Add(rb);
  i:=i+1;
   with rb do begin
      Left := Rect.Left + DBGrid1.Left +2;
      Top := Rect.Top + DBGrid1.Top + 5;
      Width := Rect.Right - Rect.Left ;
      Height := Rect.Bottom - Rect.Top - 5;
      Visible := True;
    end;
    DBGrid1.DefaultDrawDataCell(rect,field,state);
end;
Refresh;
end;

// works just fine
0
 
GhitzaAuthor Commented:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked : array[Boolean] of Integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
    if (Column.Field.FieldName = 'Round') then
    with ProgressBar1 do begin
      Left := Rect.Left + DBGrid1.Left + 1;
      Top := Rect.Top + DBGrid1.Top + 4;
      Width := Rect.Right - Rect.Left + 2;
      Width := Rect.Right - Rect.Left + 2;
      Height := Rect.Bottom - Rect.Top - 3;
      Position:=23;
      Visible := True;
    end;
end;
0
 
GhitzaAuthor Commented:
I really need it to show independent progressbars in each cell of that column because every Progressbar will have a certain Max value, min value and position...
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
GhitzaAuthor Commented:
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object DBGrid1: TDBGrid
    Left = 4
    Top = 4
    Width = 677
    Height = 381
    DataSource = DataSource1
    TabOrder = 0
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
    OnDrawColumnCell = DBGrid1DrawColumnCell
  end
  object ProgressBar1: TProgressBar
    Left = 32
    Top = 400
    Width = 150
    Height = 16
    TabOrder = 1
  end
  object ado: TADOConnection
    Connected = True
    ConnectionString =
      'Provider=MSDASQL.1;Persist Security Info=False;Data Source=xlubr' +
      'i'
    LoginPrompt = False
    Left = 120
    Top = 20
  end
  object ADOQuery1: TADOQuery
    Active = True
    Connection = ado
    CursorType = ctStatic
    Parameters = <>
    SQL.Strings = (

        'select id,dataload,dataend,dataend-dataload as zile from punct_l' +
        'ubri')
    Left = 168
    Top = 20
  end
  object DataSource1: TDataSource
    DataSet = ADOQuery1
    Left = 232
    Top = 24
  end
end
0
 
GhitzaAuthor Commented:
Give me some working code pls.
I really need it fast
0
 
calinutzCommented:
Try to store the progressbars in a TList.
Something like:
On FormCreate:
begin
LST := TList.Create;
i:=0;
end;

on Draw something like :
var
 pb : TProgressBar;
begin
if (Column.Field.FieldName = 'Round') then
begin
  pb := TProgressBar.Create(Self);
  pb.Name := 'pb' + inttostr(i);
  pb.Parent:=DBGrid1;
  pb.Smooth:=true;
  Lst.Add(pb);
  i:=i+1;
    with pb do begin
      Left := Rect.Left + DBGrid1.Left +1;
      Top := Rect.Top + DBGrid1.Top +1;
      Width := Rect.Right - Rect.Left + 2;
      Width := Rect.Right - Rect.Left + 2;
      Height := Rect.Bottom - Rect.Top - 3;
      Visible := True;
    end;
end;


// Did not try it... just from the head
0
All Courses

From novice to tech pro — start learning today.