Solved

StringGrid selection

Posted on 1998-08-11
3
1,048 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now