3

I have a Delphi DBGrid that looks normal when it first loads. I have setup an OnTitleClick event that sorts the DBGrid by the column when the title is clicked. As soon as you click on the title, the column title acts like a button being pressed and an ugly black line appears. (See Fig. 2 below)

As soon as the click event is done, the grid looks normal again.

How do you prevent this black line from appearing when you click the column title?

enter image description here

EDIT: QC Submitted to Embarcadero

While turning off the ability to resize columns does make the black line behavior disappear it does take away a very nice feature. I think this behavior needs to be fixed. I have submitted the following QC 98255 to Embarcadero. Please vote for this entry.

UPDATE: 2017-07-30

I found where this horizontal black line is being drawn.
Vcl.Grids > procedure TCustomGrid.DrawMove;

The Canvas.Pen.Width is set to 5. I changed it so the Canvas.Pen.Width := 1;
It looks much so much better. Now when I clicked on the "Contact_Last" title cell the black indicator line is just one pixel wide and much less intrusive.

enter image description here

procedure TCustomGrid.DrawMove;
var
  OldPen: TPen;
  Pos: Integer;
  R: TRect;
begin
  OldPen := TPen.Create;
  try
    with Canvas do
    begin
      OldPen.Assign(Pen);
      try
        Pen.Style := psDot;
        Pen.Mode := pmXor;
        //+----------------------------------------------------------------+
        // Modified 2017-07-30 by Michael J Riley (MJR)
        // Changed Pen.Width from 5 to 1
        // This makes the vertical black move-indicator line 1 pixel wide
        // Which is the same width as column resize vertical line
        //+----------------------------------------------------------------+
        //Pen.Width := 5;
        Pen.Width := 1;
        if FGridState = gsRowMoving then
        begin
          R := CellRect(0, FMovePos);
          if FMovePos > FMoveIndex then
            Pos := R.Bottom else
            Pos := R.Top;
          MoveTo(0, Pos);
          LineTo(ClientWidth, Pos);
        end
        else
        begin
          R := CellRect(FMovePos, 0);
          if FMovePos > FMoveIndex then
            if not UseRightToLeftAlignment then
              Pos := R.Right
            else
              Pos := R.Left
          else
            if not UseRightToLeftAlignment then
              Pos := R.Left
            else
              Pos := R.Right;
          MoveTo(Pos, 0);
          LineTo(Pos, ClientHeight);
        end;
      finally
        Canvas.Pen := OldPen;
      end;
    end;
  finally
    OldPen.Free;
  end;
end;
  • Not having Delphi in front of me (and swearing in 1999 that I'd never use a data bound control ever again) it looks like a column reorder insert marker. Is there an "allow column moving" property? – Ian Boyd Aug 28 '11 at 03:02
  • @Ian - There's a boolean option called dgColumnResize. When true it produces the black line. When false it works great. No black line. No column title button-down action either. Thank you. Make this an answer and I'll vote for it. – Michael Riley - AKA Gunny Aug 28 '11 at 03:08

1 Answers1

4

The black line looks like a column order insert marker.

Try looking for an option that disables column re-ordering.

Ian Boyd
  • 220,884
  • 228
  • 805
  • 1,125
  • It's actually called dgColumnResize. When set to True the black line appears and the title acts like a button. When set to False there is no black line and the title does not down-press like a button. Don't give up on data bound controls until you have read Cary Jensens new book "Delphi in Depth: ClientDataSets". – Michael Riley - AKA Gunny Aug 28 '11 at 03:31
  • if you turn of dgColunmResize you are taking away two vital activities that users (I'm including myself) really like. 1.) The ability to resize columns 2.) The ability to move columns. The other nice feature that goes away... The Title Cell DOES NOT depress like a button when it gets clicked. – Michael Riley - AKA Gunny Jul 30 '17 at 23:33