2

是否可以将该箭头指针添加到 Delphi 7 中的 String Grind 中?您知道我的意思,您可以在 DBGrid 左侧看到的那个箭头指针。

4

2 回答 2

4

是的,但不是自动的。您需要手动显示一个三角形。您可以为您的网格覆盖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;

这会在框中绘制一个三角形。你应该得到一般的想法。

于 2013-04-19T00:18:30.750 回答
1

不是自动的;它不是标准的一部分TStringGrid。“箭头指针的东西”被称为row indicator,它是在TDBGrid. 它在 中声明TDBGridOptions,具体dgIndicator如下所示:

TDBGridOption = (dgEditing, dgAlwaysShowEditor, dgTitles, dgIndicator,
    dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect,
    dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgMultiSelect);

请注意,这与单元中TGridOption声明的不同Grids,后者不包含任何类似内容。(没有goIndicator或等效的。)

为了获得指标,您必须自己绘制它,OnDrawCell以防您收到与该ACol值相等的值。在这个答案中有一个示例,尽管它演示了设置自定义行高而不是绘制行指示器。0ARowGrid.RowTStringGrid.OnDrawCell

于 2013-04-19T00:09:28.520 回答