Ticket T334829
Visible to All Users

How to define a custom cell color

created 9 years ago

I am displaying a table in a btvView.  When the value in the 'Code' column = '1' I want two columns (the 'Lastname' column and the 'Firstname' column to have red backgrounds and white text.  I have the following code in the OnCustomDrawCell event:
if ( TcxGridDBBandedColumn( AViewInfo.Item.DataBinding.FieldName = 'Code' ) and ( AViewInfo.Value = '1' ) then
if ( TcxGridDBBandedColumn( AViewInfo.Item ).DataBinding.FieldName = 'Lastname') or
  ( TcxGridDBBandedColumn(AViewInfo.Item ).DataBinding.FieldName = 'Firstname') ) then
begin
   AViewInfo.EditViewInfo.BackgroundColor := clRed;
  AViewInfo.EditViewInfo.TextColor := clWhite;
end;
AViewInfo.EditViewInfo.Paint( ACanvas );
ADone := true;

This appropriately paints either the 'Lastname', column or the 'Firstname' column but not both according to which one is in focus.  How can I make both columns paint as specified?

Thanks,
Jim Sawyer

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hello Jim,

I think that the custom drawing approach is too "heavy" for this task. If you wish to change only the cell's background and text colors, it is more convenient to use the Styles.OnGetContentStyle event. Attached is a small sample project demonstrating how to implement the appearance you need.

    Comments (1)

      Thank you.
      Jim Sawyer

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.