Solved

BCB DataGrid Highlight not wanted

Posted on 2011-02-27
2
610 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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: …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

726 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