Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

BCB DataGrid Highlight not wanted

Posted on 2011-02-27
2
Medium Priority
?
615 Views
Last Modified: 2013-11-17
I have an applcation written in BCB5 which uses a DBGrid control.
The problem I have is that there is always one cell of the DBGrid control highlighted in dark blue, which changes when a mouse click is madr on another cell.
The only way I can get this highlight to dissapear is to Disable the DataGrid control but this has the unwanted side effect of greying out the text in the DBGrid display.
Is there a way of displaying the text in the DBGrid normally (not greyed out) when the DBGrid control is disabled ?
Alternatively,can the Highlighting of the selected cell be turned off ?
I am using an OnDrawColumnCell event handler and I have set the read-only property of the DBGrid to true and the Options properties "RowSelect" , and "dgEditing" both to false.

I have asked this question before and I solved it myself but have forgotten how.
0
Comment
Question by:alcindor
[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: 34995064
You just have to override the color settings in OnDrawColumnCell.  Here's a quick example,

void __fastcall TMainForm::DBGrid1DrawColumnCell(TObject *Sender,
      const TRect &Rect, int DataCol, TColumn *Column,
      TGridDrawState State)
{
  TDBGrid *Grid = (TDBGrid *)Sender;

  if(State.Contains(gdSelected) == true)
  {
      Grid->Canvas->Font->Color = clBlack;
      Grid->Canvas->Brush->Color = clWhite;
   }
   else
   {
      Grid->Canvas->Font->Color = clBlack;
      Grid->Canvas->Brush->Color = clWhite;
    }
  Grid->DefaultDrawColumnCell(Rect,DataCol,Column,State);
}

The brush color is the background.  

You can turn off the automatic cell coloring but only when the grid does not have focus through the dgAlwaysShowSelected in the grid options.
0
 
LVL 2

Author Closing Comment

by:alcindor
ID: 34996456
Thanks for that!
Your test for gdSelected would appear redundant as the code in the else statements is the same in both sections ?

  if(State.Contains(gdSelected) == true)
  {
      Grid->Canvas->Font->Color = clBlack;
      Grid->Canvas->Brush->Color = clWhite;
   }
   else
   {
      Grid->Canvas->Font->Color = clBlack;
      Grid->Canvas->Brush->Color = clWhite;
    }
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

609 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