【问题标题】:Custom dbgrid and Picklist issue自定义 dbgrid 和 Picklist 问题
【发布时间】:2016-10-26 22:05:12
【问题描述】:

我正在创建自己的 DBGRid,它工作正常,除了选择列表。无论为网格设置什么按钮样式,它总是显示就地编辑器,既不是选择列表也不是椭圆按钮!

我想不出我正在做的错误:(。这是相关代码:

function TMyDBGrid.CreateEditor: TInplaceEdit;

begin
result:=TInplaceEdit.Create(self);

end;

function TMyDBGrid.GetEditStyle(ACol, ARow: integer): TEditStyle;
begin
 case Columns[ACol].ButtonStyle of
  cbsAuto : Result:=esPickList;
  cbsNone : result:=esSimple;
  cbsEllipsis : result:=esEllipsis;
end;
end;

而构造函数和析构函数只是调用 inherited ,构造函数只是为网格设置一些颜色。

【问题讨论】:

    标签: delphi subclassing dbgrid picklist


    【解决方案1】:

    没有选择列表或按钮的原因是您使用TInplaceEdit 作为不支持您需要的功能的单元格编辑器。

    TDBGrid 使用继承自TInplaceEditListTDBGridInplaceEdit 作为其就地编辑器,该编辑器为其下拉列表集成了TCustomListbox,并绘制和管理编辑按钮。

    【讨论】:

    • 但有一个问题:我尝试使用 TDBGridInplaceEdit,但它是在 DBgrids 单元的实现部分中声明的。除了更改 Delphi 源之外,还有什么方法可以使用它?
    • @DrW - 这确实是个问题。您可以尝试从更接近 TGridInplaceEdit 的 TInplaceEditList 派生您的就地编辑器,然后通过查看 TGridInplaceEdit 的 VCL 源来添加缺少的功能。但我也不确定这是否会起作用,在 dbgrid 源代码中有硬转换将编辑器转换为 TGridInplaceEdit。
    • 考虑就您实际尝试解决的问题提出问题。然后可能有其他方法可以替换编辑器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2012-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多