Solved

StringGrid selection

Posted on 1998-08-11
3
1,057 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
[X]
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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