?
Solved

StringGrid: Centered Justifying

Posted on 2003-03-31
6
Medium Priority
?
679 Views
Last Modified: 2009-07-29
The second of two quick questions. Is it possible to have all the cells in a stringgrid have their data center justified? Currently they all left-justify.
0
Comment
Question by:MartinC
6 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 8243102
Hi MartinC,
use onDrawCell event to draw cell with your style.
Search in this TA by keyword onDrawCell to get samples.

____
Igor
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 8243553
Read next article:
Aligning cells in stringgrid

http://www.delphi3000.com/article.asp?ID=1758
0
 

Author Comment

by:MartinC
ID: 8243659
Hmmmm. Thanks for this ... I was actually looking for something like

stringgrid.Justify := Centre

... which is how many other displays seem to handle it. The trouble with using DrawCell is that it gets called once per cell per redraw which seems a huge waste of resources when I really only want to set it once on creation.
0
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!

 
LVL 9

Expert Comment

by:ITugay
ID: 8243688
Hi MartinC,

>> huge waste of resources when I really only want to set it once on creation.

windows does the same. If you want to reduce redrawing, then set StringGrid.DefaultDrawing to False.

____
Igor
0
 
LVL 1

Accepted Solution

by:
nafeelm earned 63 total points
ID: 8243931
try this:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer; Rect: TRect; State: TGridDrawState);
var CellStr: String;
begin
  CellStr:=StringGrid1.Cells[Col, Row];
  SetTextAlign(StringGrid1.Canvas.Handle, TA_CENTER);
  StringGrid1.Canvas.FillRect(Rect);
  StringGrid1.Canvas.TextRect(Rect, (Rect.Left+ ((Rect.Right - Rect.Left) div 2)), Rect.Top + 2, CellStr);
  SetTextAlign(StringGrid1.Canvas.Handle, TA_LEFT);
end;

0
 

Author Comment

by:MartinC
ID: 8259479
Hmm, doesn't look like I am going to get what I am looking for. I was hoping for a simple on/off solution for the Fixed Rows.

OnDrawCell is no good because having the thing called every single time a cell is drawn makes the game probably not worth the candle. I accept ITugay's comments about Windows doing the same, but if I add a line or two of  code to an event that gets called hundreds of times, it HAS to slow everything down.

Thanks everyone. The most complete answer was nafeelm's so I will award the points there.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Loops Section Overview
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

569 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