Solved

dbGrid selected row color

Posted on 2008-10-05
2
2,816 Views
Last Modified: 2013-11-17
Hi

I am coloring each alternate row in a dbgrid with 2 different colors.  This works fine.  Please see my code below.  My problem is that when I select rows on the grid it does not show that it is selected.  All the "Allwaysshowselection" and "RowSelect" options are set to "true" so I don't think it is that.  Any ideas as to how I can show which rows are selected using the code below:

void __fastcall TfrmCardPrintSelection::dbgDLAuthoritiesDrawColumnCell(
                  TObject *Sender, const TRect &Rect, int DataCol, TColumn *Column,
                  TGridDrawState State)
{
      int l_i_OddOrEven = 0;

      l_i_OddOrEven = dbgDLAuthorities->DataSource->DataSet->RecNo % 2;

      if( l_i_OddOrEven == 0 )
      {
            dbgDLAuthorities->Canvas->Brush->Color = clSkyBlue;
            dbgDLAuthorities->Canvas->Font->Color = clWhite;
      }
      else
      {
            dbgDLAuthorities->Canvas->Brush->Color = clWhite;
            dbgDLAuthorities->Canvas->Font->Color = clBlack;
      }
      dbgDLAuthorities->DefaultDrawColumnCell( Rect, DataCol, Column, State );
}
0
Comment
Question by:WalterRautenbach
2 Comments
 
LVL 25

Accepted Solution

by:
kode99 earned 500 total points
ID: 22656465
You just need to add in a check so that you can color the selected row such that it will still show up with a decent contrast.  Depends on the look you are going for but often I find switching the brush color and the font color to invert the selected row shows up good.

So something like this,
  ....
    if( l_i_OddOrEven == 0 )
      {
          if(State.Contains(gdSelected) == true)
         {
             dbgDLAuthorities->Canvas->Brush->Color = clWhite;
             dbgDLAuthorities->Canvas->Font->Color = clSkyBlue;
          } else
           {
             dbgDLAuthorities->Canvas->Brush->Color = clSkyBlue;
             dbgDLAuthorities->Canvas->Font->Color = clWhite;
           }
      }
      else
      {
          if(State.Contains(gdSelected) == true)
         {
             dbgDLAuthorities->Canvas->Brush->Color = clBlack;
             dbgDLAuthorities->Canvas->Font->Color = clWhite;
          }else
          {
             dbgDLAuthorities->Canvas->Brush->Color = clWhite;
             dbgDLAuthorities->Canvas->Font->Color = clBlack;
           }
      }
 ....

0
 

Author Closing Comment

by:WalterRautenbach
ID: 31506006
Thank you so much,  Works perfectly!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wordlen challenge 3 61
Header of docx file 17 98
PHPStorm debugging issues 1 25
Message not shown 5 34
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

863 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

20 Experts available now in Live!

Get 1:1 Help Now