Board index » cppbuilder » Need Help, Need Help

Need Help, Need Help

In my application, I have 3 TStringGrid screen.  When I click on a
Tab1(TStringGrid1) and so on..., it will open a file and
fill in the grid.  The first row "(row 0)" is always set to color clBtFace,
because is where the title goes, the rest of the grid is white.

Three things I want to happen:

1.  When I click on the Tab, I don't want my focus to be set on any of the
rows, because I have an Event (OnDrawCell), which opens a window if the row
is focused.  How can I prevent this from happening? Or can I direct the
focus on something else?

2.  When the user does click on a row, I would like for it to be hilighted,
but if the row is white, then the letters dissapear,
they really don't dissappear, they are just white and it appear as if the
whole row just went blank.  How can I change the color or the highlight or
do something else to change this?

3.  When the user selects or places focus on a particular row, I open a
window.  When the user sees the info, he then clicks
the window off, and I would like to switch the color of that particular row
to something else than white, representing that he/she already seen that
row?

Thank you,
Neil P.

 

Re:Need Help, Need Help


Quote
Neil P. wrote:
> In my application, I have 3 TStringGrid screen.  When I click on a
> Tab1(TStringGrid1) and so on...,

As far as I know StringGridss have no Tabs. Could yoy please explain.

Further: you could have taken the time to make a good Subject.
It's awfull crying for help or please help needed as everybody
who has a question will only do that needing help.

Hans.

Re:Need Help, Need Help


I think he meant Table, not Tab. . . I think . . .

Re:Need Help, Need Help


Quote
> 1.  When I click on the Tab, I don't want my focus to be set on any of the
> rows, because I have an Event (OnDrawCell), which opens a window if the row
> is focused.  How can I prevent this from happening? Or can I direct the
> focus on something else?

You can change the focus by setting the form's ActiveControl property.

ActiveControl=<some other control>;

You could possibly also select grid row 0 and column 0 (if there are fixed rows
and fixed cols), but this still will draw an outlined frame on the 0,0 cell.

Quote
> 2.  When the user does click on a row, I would like for it to be hilighted,
> but if the row is white, then the letters dissapear,
> they really don't dissappear, they are just white and it appear as if the
> whole row just went blank.  How can I change the color or the highlight or
> do something else to change this?

You need to add code to the OnDrawCell event handler, along the line of:
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol, int
ARow,
      TRect &Rect, TGridDrawState State)
{
TColor SaveFontColor=StringGrid1->Canvas->Font->Color;
TColor SaveBrushColor=StringGrid1->Canvas->Brush->Color;

// set font and brush colors based on column number
if (ARow==0)
  {
  StringGrid1->Canvas->Font->Color=clYellow;
//  StringGrid1->Canvas->Brush->Color=clRed;
  StringGrid1->Canvas->Brush->Color=clLime;
  }
else
  {
  StringGrid1->Canvas->Font->Color=clBlue;
//  StringGrid1->Canvas->Brush->Color=clHighlight;
  StringGrid1->Canvas->Brush->Color=clWhite;
  }

// eliminate artifacts using background color
StringGrid1->Canvas->FillRect(Rect);

// render the text using font color
StringGrid1->Canvas->TextOut(Rect.Left, Rect.Top,
StringGrid1->Cells[ACol][ARow]);

// reset to default colors
StringGrid1->Canvas->Font->Color=SaveFontColor;
StringGrid1->Canvas->Brush->Color=SaveBrushColor;

Quote
}

> 3.  When the user selects or places focus on a particular row, I open a
> window.  When the user sees the info, he then clicks
> the window off, and I would like to switch the color of that particular row
> to something else than white, representing that he/she already seen that
> row.

Include code in the OnDrawCell event handler to do just that.  You will have to
keep an associated table, list, array, etc, to track which rows have been
handled, so that the OnDrawCell handler can display the cell correctly,
depending on the that state.  Remember that the OnDrawCell handler will be
called anytime the cell needs to be redrawn, such as when the form is
maximized, or another app's forms are moved over, then off of, your grid.

keith

Other Threads