Solved

BCB DataGrid Highlight not wanted

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.
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 columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

808 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