?
Solved

Very urgent DBGrid draw

Posted on 2005-03-23
6
Medium Priority
?
261 Views
Last Modified: 2010-04-05
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:
0
Comment
Question by:Ghitza
[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
  • 4
  • 2
6 Comments
 
LVL 3

Author Comment

by:Ghitza
ID: 13611281
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
 
LVL 3

Author Comment

by:Ghitza
ID: 13611290
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
 
LVL 3

Author Comment

by:Ghitza
ID: 13611354
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
Technology Partners: 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

Author Comment

by:Ghitza
ID: 13611441
Give me some working code pls.
I really need it fast
0
 
LVL 11

Expert Comment

by:calinutz
ID: 13611714
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
 
LVL 11

Accepted Solution

by:
calinutz earned 1600 total points
ID: 13611826
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

764 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