DBgrid rowcolors

Posted on 2007-07-31
Last Modified: 2013-11-23
i have a tms DBadvgrid and i show some records of my table to the dbgrid.I want to paint with diffrent color the rows that is even and with different cooor the rows that is odd for example i want the first row to have red color and the 2nd row to have green,the 3rd to have the same color with the first and the 4rth with the second row (even and odd rows...) or you can suggest me other ways to do this.

Thanks in advance.
Question by:alex_code
    LVL 24

    Expert Comment

    by:Tomas Helgi Johannsson
    LVL 15

    Accepted Solution

    For the TMS component use the OnGetCellColor event of the component

    procedure TForm1.DBAdvGrid1GetCellColor( sender: TObject; ARow,
       ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
       // ignore header
       if ARow > 0 then
          case ARow mod 2 of
             0: ABrush.color := clRed;
             1: ABrush.color := clBlue;
    LVL 9

    Author Comment

    thanks a lot... you are great!!! i 'll need you more if you know good the tms grid... ;)

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    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…
    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    754 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

    16 Experts available now in Live!

    Get 1:1 Help Now