title: Programmatically drawing the lines in a delphi drawgrid and merge cells
body: <p>I want to disable the gridlines in a drawgrid and draw the grid lines myself for every other columns. Row lines are not needed.  </p>
  
  <p>I want to merge two cells in the fixed area so that it looks like as it is one column, like in this picture:</p>
  
  <p><img src="https://i.stack.imgur.com/DW4Xo.jpg" alt="Grid with merged columns"></p>
  
  <p>I have added this code to the <code>ondrawcell</code> event of the drawgrid to achieve this:</p>
  
  <pre><code>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]) &lt;&gt; [] 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 &gt; 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;
  </code></pre>