Solved

dbGrid selected row color

Posted on 2008-10-05
2
2,874 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 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