Solved

BCB DataGrid Highlight not wanted

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

Technology Partners: 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

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…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

691 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