[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 723
  • Last Modified:

Grid to show multiple lines per cell, scheduling component.

Good Morning Experts

I need help with viewing data in a grid. Currently I am using a ExpressScheduler ver 2 component to show my data, but because I have so many resources the component become very,very slow.

What I want to show to the user are the following :

                    Sat 1 May    Sun 2 May      Mon 3 May   Tue 4 May     Wed 5 May      Thu  6 May        Fri 7 May ..
RES:    1      NAME          NAME              NAME            NAME           NAME              NAME                NAME
                    AGE            AGE                AGE              AGE              AGE                ...                       ......
                    Salary         SALARY        SALARY       SALARY

RES:    2     NAME          NAME              NAME            NAME           NAME              NAME                NAME
                   AGE            AGE                AGE              AGE              AGE                ...                       ......
                   Salary         SALARY        SALARY       SALARY

RES:    3    NAME          NAME              NAME            NAME           NAME              NAME                NAME
                  AGE            AGE                AGE              AGE              AGE                ...                       ......
                  Salary         SALARY        SALARY       SALARY

As you can see from my example, I need to show in the header all my dates, starting from a specific date, and go on as far as I like.

Then in the first Column downwards I must show all my resources, there are upto 290.
Then for each resource in each cell I must show three lines of data in a cell.

The ExpressScheduler work beautifully, but it is to slow and I dont need all the nice features, I just need to show the data in a grid as my example.

Please experts I need any suggestions or Ideas.

Thank you

  • 6
  • 2
1 Solution
Ioannis AnifantakisSoftware EngineerCommented:
if you use a string grid,
Use the onDrawCell on your string grid like this

if you do that, your cell will be resized to fit the data you put to it

procedure TCompareFieldsFRM.grid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
  S: string;
  drawrect :TRect;
    S:= (Sender as TStringgrid).Cells[aCol, aRow ];
  If Length(S) > 0 then begin
    drawrect := rect;
    DrawText((Sender as TStringgrid).canvas.handle,
              Pchar(S), Length(S), drawrect,
              dt_calcrect or dt_wordbreak or dt_left );

    If (drawrect.bottom - drawrect.top) >
       (Sender as TStringgrid).RowHeights[arow]
      (Sender as TStringgrid).RowHeights[arow] :=
         (drawrect.bottom - drawrect.top)
      // changing the row height fires the event again!
    else begin
      drawrect.Right := rect.right;
      (Sender As TStringgrid).canvas.fillrect( drawrect );
//      grid.Canvas.CopyRect(rect, TBitmap(grid.Objects[ACol, ARow]).Canvas, drawrect);
      DrawText((Sender as TStringgrid).canvas.handle,
                Pchar(S), Length(S), drawrect,
                dt_wordbreak or dt_left);
Ioannis AnifantakisSoftware EngineerCommented:
Also since you are using DevExpress you can alternatively put the data you want in a client dataset, and then show them on a cxGrid with memo property on the cells.  You can configure that to show all the lines of your text for each rendered cell :)
henryreynoldsAuthor Commented:
Hi ioannisa

Sorry for replying now. Thanx for your ideas I need to how I kan create a reference for each cell when populating my stringgrid now.

Sorry but let me explain. I am getting my data from my database table, I have the following fields.

Now my top row of my grid will have the header with a start date and a end date :
Sat 1 May    Sun 2 May      Mon 3 May   Tue 4 May     Wed 5 May      Thu  6 May        Fri 7 May .

Now when I reading my data in my grid, I need to place the correct record in the correct cell where the date match and the resource... this is my first problem.

Secondly if my data is in the grid, then when I click on a cell I need to know for what date the record is and the resource, this is why I thought when I populate my grid I must create a record or pointer for each cell to always refernce back.

I hope you understand what I am trying.


I am increasing the points
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Ioannis AnifantakisSoftware EngineerCommented:
x,y: integer;

x:=1; // my column
y:=1; // my row

StringGrid1.Cells[x,y]:='SAT 1 MON'+#13#10+'I have text'

That will draw on cell[1,1] the two lines of text I show u above.

make your StringGrid to have 0 fixed rows and columns

if you create a Grid that has 7 rows and your day starts from Saturday
then for x
1=Monday and so on

so if u wish to display something for the first row on monday you will type
StringGrid1.Cells[1,yourColumnIndex]:='your text';

or you can make
  SUNDAY: integer=0;
  MONDAY: integer=1; // and so on and then

and then
StringGrid1.Cells[MONDAY, yourColumnIndex] := 'your text';

you can get the number representing the day of week by doing the following

DayOfWeek(TDate) to retrun you number between 1 and 7 with 1 being Sunday
DayOfTheWeek(TDate) to retrun you number between 1 and 7 with 1 being Monday

so if you have Sunday as your first day then you get DayOfWeek - 1 (thats -1 because indexes are 0 based)

StringGrid1.Cells[DayOfWeek(myDate)-1, yourColumnIndex] := 'your text';
Ioannis AnifantakisSoftware EngineerCommented:
Now for your second question about clicking on a cell

if you implement the onSelectCell you get

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);


as you can see in this method you have both the col and the row
so you know you hit on the second row of the column that represents Tuesday for example :)
Ioannis AnifantakisSoftware EngineerCommented:
Also reference on cell

You can create a two dimentional array that holds X and Y and have that array type be a a RECORD type on delphi.  Since each array cell will hold one such record you can store as much information you like there and retrieve it by the same X,Y as the one where you click.

Alternatively you can create a client dataset to hold the some data.
Assume you put on the FieldDefs of the clientDataSet the following
X: integer
Y: integer
dateRelated: TDate
Descr: String
SomeMoreInfo: String

if you now put that client dataset's property Filtered=True
then you can apply filter:='X=1 and Y=2' and.... there you go... you get all the fields for just the equivalent cell you have clicked ;)
Ioannis AnifantakisSoftware EngineerCommented:
And another final idea about referencing your StringGrid...

you can additionally put another StringGrid that is not visible and hold on the same cells more info you would like.  So once you click on the visible cell, reference the equivalent cells on the invisible grid... Again yet another way to reference some values maybe  :)

Hope I haven't made your head explode by my ideas... lol
henryreynoldsAuthor Commented:
Hi ioannisa

I just got back from dr. will look at your idea now, thank you very very much


Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now