简体   繁体   English

如何从Delphi DBGrid OnTitleClick事件中删除黑线?

[英]How do you Remove the Black Line from a Delphi DBGrid OnTitleClick Event?

I have a Delphi DBGrid that looks normal when it first loads. 我有一个Delphi DBGrid,它在第一次加载时看起来很正常。 I have setup an OnTitleClick event that sorts the DBGrid by the column when the title is clicked. 我已经设置了一个OnTitleClick事件,在单击标题时按列对DBGrid进行排序。 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) (见下图2)

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? 单击列标题时如何防止出现黑线?

在此输入图像描述

EDIT: QC Submitted to Embarcadero 编辑:QC提交给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. 我已将以下QC 98255提交给Embarcadero。 Please vote for this entry. 请投票支持此条目。

UPDATE: 2017-07-30 更新时间:2017-07-30

I found where this horizontal black line is being drawn. 我发现了这条水平黑线的绘制位置。
Vcl.Grids > procedure TCustomGrid.DrawMove; Vcl.Grids > 程序 TCustomGrid.DrawMove;

The Canvas.Pen.Width is set to 5. I changed it so the Canvas.Pen.Width := 1; Canvas.Pen.Width设置为5.我更改了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. 现在,当我点击“Contact_Last”标题单元格时,黑色指示线只有一个像素宽,而且侵入性更小。

在此输入图像描述

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;

The black line looks like a column order insert marker. 黑线看起来像列顺序插入标记。

Try looking for an option that disables column re-ordering. 尝试寻找禁用列重新排序的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM