Solved

dbGrid selected row color

Posted on 2008-10-05
2
2,830 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 96
Arduino EDI - Programming language 3 95
C++ mouse_event mouse look 7 83
How do i run a c++ file? 15 29
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 columnThat will then direct you to their download page.From that page s…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.

810 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