Delphi TStringGrid中的箭头指针

Delphi TStringGrid中的箭头指针,delphi,delphi-7,Delphi,Delphi 7,在Delphi7中是否可以将箭头指针添加到字符串研磨中?你知道我的意思,你可以在DBGrid中看到左边的箭头;它不是标准TStringGrid的一部分。“箭头指针”被称为行指示器,它是在TDBGrid中添加的一项功能。它在TDBGridOptions中声明,特别是dgIndicator,如下所示: TDBGridOption = (dgEditing, dgAlwaysShowEditor, dgTitles, dgIndicator, dgColumnResize, dgColLine

在Delphi7中是否可以将箭头指针添加到字符串研磨中?你知道我的意思,你可以在DBGrid中看到左边的箭头;它不是标准
TStringGrid
的一部分。“箭头指针”被称为
行指示器
,它是在
TDBGrid
中添加的一项功能。它在
TDBGridOptions
中声明,特别是
dgIndicator
,如下所示:

TDBGridOption = (dgEditing, dgAlwaysShowEditor, dgTitles, dgIndicator,
    dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect,
    dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgMultiSelect);
请注意,这与
网格
单元中声明的
TGridOption
不同,后者不包含任何类似内容。(没有
goIndicator
或等效物。)


为了获得指示器,当您收到
ACol
0
ARow
相当于
网格.Row
值时,您必须自己在
OnDrawCell
事件中绘制指示器。中有一个示例
TStringGrid.OnDrawCell
,不过它演示了如何设置自定义行高度,而不是绘制行指示器。

是,但不是自动绘制的。您需要手动显示三角形。您可以为网格覆盖OnDrawCell。似乎需要将FixedCols设置为0,因为当行选择更改时,它不会再次重新绘制固定单元格

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  aCanvas: TCanvas;
  oldColor: TColor;
  triangle: array [0..2] of TPoint;
const
  spacing = 4;
begin
  if (ACol = 0) and (aRow = StringGrid1.Row) then
  begin
    aCanvas := (Sender as TStringGrid).Canvas;  // To avoid with statement
    oldColor := aCanvas.Brush.Color;
    // Shape the triangle
    triangle[0] := TPoint.Create(Rect.Left + spacing, Rect.Top + spacing);
    triangle[1] := TPoint.Create(Rect.Left + spacing, Rect.Top + Rect.Height - spacing);
    triangle[2] := TPoint.Create(Rect.Left + Rect.Width - spacing, Rect.Top + Rect.Height div 2);

    // Draw the triangle
    aCanvas.Pen.Color := clBlack;
    aCanvas.Brush.Color := clBlack;
    aCanvas.Polygon(triangle);
    aCanvas.FloodFill(Rect.Left + Rect.Width div 2, Rect.Top + Rect.Height div 2, clBlack, fsSurface);
    aCanvas.Brush.Color := oldColor;
  end;
end;

这将在框中绘制一个三角形。你应该知道大概的意思。

请不要在标签中包含的标题(如“(Delphi 7)”中添加信息。标签系统在这里工作得非常好,没有必要重复主题中的信息。谢谢。:-)+这对我帮助很大。BTW在BDS2006 C++中不需要乱用固定列(所以在Delphi中最有可能是相同的)。它们以这种方式渲染为其余单元。唯一需要做的事情是使用
TStringGrid
的OnMouseDown事件对点击它们进行编程。我的项目刚刚获得id(MYSQL表TStringGrid,带有自定义排序和嵌套表规则)