Solved

BCB DataGrid Highlight not wanted

Posted on 2011-02-27
2
605 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
2 Comments
 
LVL 25

Accepted Solution

by:
kode99 earned 500 total points
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
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.

744 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

12 Experts available now in Live!

Get 1:1 Help Now