Solved

Column Alignment Setting in StringGrid

Posted on 2001-08-21
3
544 Views
Last Modified: 2010-04-06
I'd like to set a column alignment in a StringGrid component. Can Anyone tell me how to set it?

ysimon
0
Comment
Question by:ysimon
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
zebada earned 50 total points
ID: 6411342
I derive a component called TIniGrid from TStringGrid and override the DrawCell method. I also include an array of justification settings called FJustify[] that holds the justification settings for each column.

procedure TIniGrid.DrawCell(ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  t: string;
  just: UINT;

  begin
  Canvas.Font.Color := Font.Color;
  if ( gdFixed in State ) then
    Canvas.Brush.Color := FixedColor
  else
    if ( gdSelected in State ) then
    begin
      Canvas.Brush.Color := clHighLight;
      Canvas.Font.Color := clHighLightText;
    end
    else
      Canvas.Brush.Color := Color;
  Canvas.FillRect(Rect);

  if ( (ACol<FixedCols) or (ARow<FixedRows) ) then
  begin
    Canvas.Pen.Style := psSolid;
    Canvas.Pen.Color := clBtnShadow;
    Canvas.MoveTo(Rect.Left,Rect.Bottom-1);
    Canvas.LineTo(Rect.Right-1,Rect.Bottom-1);
    Canvas.LineTo(Rect.Right-1,Rect.Top);
    Canvas.Pen.Color := clBtnHighlight;
    Canvas.LineTo(Rect.Left,Rect.Top);
    Canvas.LineTo(Rect.Left,Rect.Bottom-1);
  end;

  t := Cells[ACol,ARow];
  Rect.Top := Rect.Top + 2;
  Rect.Left := Rect.Left + 2;
  Rect.Right := Rect.Right - 4;
  Rect.Bottom := Rect.Bottom - 2;
  case ( FJustify[ACol] ) of
    taLeftJustify:
      just := DT_LEFT;
    taCenter:
      just := DT_CENTER;
    taRightJustify:
      just := DT_RIGHT;
    else
      just := DT_LEFT;
  end;
  DrawText(Canvas.Handle,PChar(t),Length(t),Rect,just);
end;



0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6872397
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.11866558.html
http://www.experts-exchange.com/questions/Q.20107980.html
http://www.experts-exchange.com/questions/Q.20112507.html
http://www.experts-exchange.com/questions/Q.20121203.html
http://www.experts-exchange.com/questions/Q.20122370.html
http://www.experts-exchange.com/questions/Q.20128022.html
http://www.experts-exchange.com/questions/Q.20128024.html
http://www.experts-exchange.com/questions/Q.20143035.html
http://www.experts-exchange.com/questions/Q.20145949.html
http://www.experts-exchange.com/questions/Q.20164917.html
http://www.experts-exchange.com/questions/Q.20164983.html
http://www.experts-exchange.com/questions/Q.20171798.html
http://www.experts-exchange.com/questions/Q.20179154.html
http://www.experts-exchange.com/questions/Q.20192667.html
http://www.experts-exchange.com/questions/Q.20192583.html
http://www.experts-exchange.com/questions/Q.20200806.html
http://www.experts-exchange.com/questions/Q.20201786.html
http://www.experts-exchange.com/questions/Q.20201947.html
http://www.experts-exchange.com/questions/Q.20246959.html
http://www.experts-exchange.com/questions/Q.20252474.html
http://www.experts-exchange.com/questions/Q.20259886.html
http://www.experts-exchange.com/questions/Q.20270462.html
http://www.experts-exchange.com/questions/Q.20273241.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20265181.html
http://www.experts-exchange.com/questions/Q.20277546.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7079716
Zero response from anyone, finalized.
Moondancer - EE Moderator
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now