Solved

Programmatically drawing the lines in a delphi drawgrid and merge cells

Posted on 2013-06-27
9
1,263 Views
Last Modified: 2013-09-03
0 down vote favorite
	

I want to disable the gridlines in a drawgrid and draw the grid lines myself for every other columns. Row lines are not needed.

I want to merge two cells in the fixed area so that it looks like as it is one column, like in this picture:drawgrid how i want to look like
the attached code i have inserted to ondrawcell event of the dragrid

 procedure Tbookings3_Frm.bgridDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  CellIndex: Integer;
    s:string;
  x:integer;
begin
  CellIndex := (ARow * bgrid.ColCount) + ACol;

  if gdFixed in State then
  begin
    bgrid.Canvas.Brush.Color := clskyblue;
  end
  else if (State * [gdSelected, gdHotTrack]) <> [] then
  begin
    bgrid.Canvas.Brush.Color := clHighlight;
  end
  else
  begin
    bgrid.Canvas.Brush.Color := Cells[CellIndex].BkColor;
  end;



  bgrid.Canvas.FillRect(Rect);

  if gdFixed in State then
    Frame3D(bgrid.Canvas, Rect, clHighlight, clBtnShadow, 1);

  if gdFocused in State then
    bgrid.Canvas.DrawFocusRect(Rect);

//---------------

  with (Sender as TDrawGrid).Canvas do
  begin
     // set font
    Font.Color := CLblack;
    FillRect(Rect);

    if ARow = 2 then
    begin
        x := (Rect.Right - Rect.Left - TextWidth(days_h[ACol])) div 2;
        TextOut(Rect.Left + x, Rect.Top + 2, days_h[ACol]);
    end;
  if ARow = 1 then
     begin
       x := (Rect.Right - Rect.Left - TextWidth(sun_mon[ACol])) div 2;
       TextOut(Rect.Left + x, Rect.Top + 2, sun_mon[ACol]);

     end;
  if ARow = 0 then
     begin
        x := (Rect.Right - Rect.Left - TextWidth(mon[ACol])) div 2;
        TextOut(Rect.Left + x, Rect.Top + 2, mon[ACol]);
      end;

  if (Acol = 0) and (ARow > 2) then
     begin
        s:=rooms[Arow];
        x := (Rect.Right - Rect.Left - TextWidth(s)) div 2;
        TextOut(Rect.Left + x, Rect.Top + 2, s);
     end;

//-------------------------------------------------



  end; //end canvas
//----------------
  if gdFocused in State then
    bgrid.Canvas.DrawFocusRect(Rect);
end;

Open in new window

0
Comment
Question by:thooloon
  • 2
  • 2
9 Comments
 
LVL 21

Expert Comment

by:developmentguru
ID: 39283309
Wow, I have some questions.

Could you tel us a bit more about, exactly, what you are trying to accomplish?  Knowing that my point to an easier solution.

Have you considered that even if you get the cells to merge graphically that some of the other behavior will be... troublesome?  As an example, were you planning on ignoring every other cell so, say, only the even number cells get drawn?  Should the cells be drawn normally just with every other cell line?

Might you want a solution that allows for customization in the future?  Knowing what you are trying to accomplish would help with this question too...

What version of Delphi are you using?
0
 
LVL 1

Author Comment

by:thooloon
ID: 39283466
I am using Delphi XE3. The merged cells are on the fixed rows. Every two column represent 1 day of the calendar. The rows represent room numbers. Basically it's a room bookings. One column represent half day. That's why the grid lines are drawn in every other columns.
0
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39302840
I suggest to use KGrid:
http://www.torry.net/authorsmore.php?id=5878
... it supports cell merging. Install component and run included demo to see how it looks.
0
 
LVL 1

Author Comment

by:thooloon
ID: 39304823
i would like to have some codes instead of a component
0
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39306437
This feature as merging cells must be implemented very "under" - so component is right way. Don't be afraid of components.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 70
Adoquery sql  left join does not work 25 80
This code tracks birthdays 3 60
Interview question Javascript, database 12 31
A short article about a problem I had getting the GPS LocationListener working.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

15 Experts available now in Live!

Get 1:1 Help Now