Board index » cppbuilder » TStringGrid: No full blue cell while disabled

TStringGrid: No full blue cell while disabled

Hi
I have a form with several components. Dynamically I create a
TStringGrid component. Until TStringGrid has not the focus always the
cell [1][1] is completely blue painted with a white font. How can I kill
this behaviour and have only black font on white background ?

The StringGrid is for editing numbers for calculation and the Options
property contains goEditing and goAlwaysShowEditor.

I alread have tried a solution similar like from Peter Below in Delphi
newsgroup in the constructor of TStringGrid

TGridRect NoSel;
NoSel.Left   =-1;
NoSel.Top  =-1;
NoSel.Right =-1;
NoSel.Bottom =-1;
Selection = NoSel;

But then after entering in TStringGrid an error occurs for index out of
range (roughly translated).
Do you know a solution?

Thank you very much in advance.
Tilmann

 

Re:TStringGrid: No full blue cell while disabled


Tilman:

The following coding does work with one exception.

TGridRect NoSel;
NoSel.Left   =-1;
NoSel.Top  =-1;
NoSel.Right =-1;
NoSel.Bottom =-1;
Selection = NoSel;

If your TStringGrid gets the focus after this and allows keyboard input it
will try to get input from the cell that doesn't exist thus the error. You
can catch this in your OnKeyDown event.

OnKeyDown()
{
 if(TStringGrid->Selection.TopLeft.X==-1)
 {
  Key=0;
  return;
 }

You might have to do the same with the OnKeyPress() event.

Hope that helps..

John

--
Use file security for your password and regular applications. Find out how
at http://home.att.net/~special_projects/security.htm
It's Free!

Get The File Editor Professional
http://home.att.net/~special_projects/TheFileEditorProfessional.htm

Join the Shareware Authors Assessment Team see
http://home.att.net/~special_projects/home.htm for more information.

Quote
Tilmann Kraemer <Tilmann_u_Elke_Krae...@t-online.de> wrote in message

news:388CA946.B40B98B3@t-online.de...
Quote
> Hi
> I have a form with several components. Dynamically I create a
> TStringGrid component. Until TStringGrid has not the focus always the
> cell [1][1] is completely blue painted with a white font. How can I kill
> this behaviour and have only black font on white background ?

> The StringGrid is for editing numbers for calculation and the Options
> property contains goEditing and goAlwaysShowEditor.

> I alread have tried a solution similar like from Peter Below in Delphi
> newsgroup in the constructor of TStringGrid

> TGridRect NoSel;
> NoSel.Left   =-1;
> NoSel.Top  =-1;
> NoSel.Right =-1;
> NoSel.Bottom =-1;
> Selection = NoSel;

> But then after entering in TStringGrid an error occurs for index out of
> range (roughly translated).
> Do you know a solution?

> Thank you very much in advance.
> Tilmann

Re:TStringGrid: No full blue cell while disabled


Hi Tilmann,

Quote
> I have a form with several components. Dynamically I create a
> TStringGrid component. Until TStringGrid has not the focus always the
> cell [1][1] is completely blue painted with a white font. How can I kill
> this behaviour and have only black font on white background ?

You can set the StringGrid's DefaultDrawing property to false, then render the
contents of the grid yourself in a handler for the OnDrawCell event.  In this
case, simply ignore (i.e., don't render) the selected state.  Here's an
example...

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, long Col, long Row,
    TRect &Rect, TGridDrawState State)
{
    // fixed rows/cols
    if (State.Contains(gdFixed))
    {
        StringGrid1->Canvas->Brush->Color = clBtnFace;
        StringGrid1->Canvas->Font->Color = clWindowText;
        StringGrid1->Canvas->FillRect(Rect);
        Frame3D(StringGrid1->Canvas, Rect, clBtnHighlight,
                clBtnShadow, 1);
    }

    // normal
    else
    {
        StringGrid1->Canvas->Brush->Color = StringGrid1->Color;
        StringGrid1->Canvas->Font->Color = StringGrid1->Font->Color;
        StringGrid1->Canvas->FillRect(Rect);
    }

    AnsiString text = StringGrid1->Cells[Col][Row];
    StringGrid1->Canvas->TextRect(Rect, Rect.Left, Rect.Top, text);

Quote
}

Alternatively, the following may work...

// TForm::OnShow event handler:
void __fastcall TForm1::FormShow(TObject *Sender)
{
    StringGrid1->EditorMode = true;    

Quote
}

Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Other Threads