Grid to show multiple lines per cell, scheduling component.

Posted on 2007-08-01
Last Modified: 2010-04-05
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

Question by:henryreynolds
    LVL 6

    Expert Comment

    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 - >
           (Sender as TStringgrid).RowHeights[arow]
          (Sender as TStringgrid).RowHeights[arow] :=
             (drawrect.bottom -
          // 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);
    LVL 6

    Expert Comment

    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 :)

    Author Comment

    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
    LVL 6

    Expert Comment

    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';
    LVL 6

    Expert Comment

    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 :)
    LVL 6

    Expert Comment

    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 ;)
    LVL 6

    Accepted Solution

    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

    Author Comment

    Hi ioannisa

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    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…
    Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now