?
Solved

StringGrid selection

Posted on 1998-08-11
3
Medium Priority
?
1,062 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 80 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

Industry Leaders: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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