Solved

StringGrid selection

Posted on 1998-08-11
3
1,052 Views
Last Modified: 2008-02-01
I'm using a StringGrid to display some strings. I don't want the user to alter the values. However I see one cell with the color of the selection (?). My question is. How can I make all the cells look the same (clWhite). When I move focus to the StringGrid the selected colored cell changes to a dotted square with the same color as all the other cells. Hope I don't have to use tricks like OnDrawCell.
0
Comment
Question by:detempel
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 20 total points
ID: 1361932
Hi detempel,

If you don't want to use OnDrawCell event, then I think we've got a problem?
 Because if focus is moved away from grid, cell will be coloured.

I advise you to look at these two freeware grids, which are far better then the one of Inprise itself :

SuperGrid and/or Hypergrid.

http://www.pablop.demon.co.uk/ with this you can easely change (with visible properties) the layout of the grid, selected cell, ...

Regards, Zif.
0
 

Author Comment

by:detempel
ID: 1361933
Hello Zif,

I don't want to use external components for reasons of maintenance. So I guess I'll have to use the OnDrawCell-event. Can you or someone else give me an example of how to write such an event. I've tried something myself but I'm not yet satisfied with the result and not sure of all the possibilities.

Regards,
The Temple.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361934
Hi detempel, here is the code for ondraw-event

procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
  Rect: TRect; State: TGridDrawState);
const
  LM = 3; {each indiviual cell's left margin}
  TM = 2; {each indiviual cell's top margin}
begin
  if gdFixed in State then {draw fixed columns , fixed}
     (sender as TStringGrid).Canvas.Brush.Color :=
       (sender as TStringGrid).FixedColor;
  if (gdSelected in State) then {draw selected cell , normal}
    begin
      (sender as TStringGrid).Canvas.Brush.Color :=
          (sender as TStringGrid).Color;
      (sender as TStringGrid).Canvas.Font.Color :=
          (sender as TStringGrid).Font.Color;
    end;
  {finally, do the actual cell drawing}
  (sender as TStringGrid).Canvas.TextRect(Rect, Rect.Left + LM, Rect.Top + TM, (sender as TStringGrid).Cells[col,row]);
end;

Regards, Zif.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 98
Delphi cmd execution 6 60
Adoquery sql  left join does not work 25 91
How to convert memory stream to PDF file 6 59
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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