?
Solved

dbGrid selected row color

Posted on 2008-10-05
2
Medium Priority
?
2,886 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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 viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

765 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