Solved

dbGrid selected row color

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

758 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

22 Experts available now in Live!

Get 1:1 Help Now