?
Solved

StringGrid: Centered Justifying

Posted on 2003-03-31
6
Medium Priority
?
674 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
[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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

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