Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

StringGrid selection

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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