【问题标题】:How to disable TListView edit on item click?如何在项目单击时禁用 TListView 编辑?
【发布时间】:2014-07-06 19:56:56
【问题描述】:

我想在单击 TListView 选定项目时禁用进入编辑模式,但不完全禁用它(设置属性 ReadOnly=True)。我希望仍然能够通过其他方法对其进行编辑。有可能吗?

【问题讨论】:

    标签: delphi edit delphi-6 tlistview


    【解决方案1】:

    我没有看到任何简单的方法来准确检测LVN_BEGINLABELEDIT 通知是如何出现的。触发列表视图就地编辑的是LVN_BEGINLABELEDIT 通知。

    所以,我认为您可能需要想出一个稍微老套的解决方案。在表单中添加一个Boolean 字段,例如命名为FCanEditListView。然后,无论您在哪里触发编辑模式,都在触发编辑模式之前设置此标志 True,然后将其恢复为 False

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Item: TListItem;
    begin
      Item := ListView1.Selected;
      if Assigned(Item) then
      begin
        FCanEditListView := True;
        Item.EditCaption;
        FCanEditListView := False;
      end;
    end;
    

    然后为列表视图的OnEditing 事件添加一个处理程序,以像这样切换行为:

    procedure TForm1.ListView1Editing(Sender: TObject; Item: TListItem;
      var AllowEdit: Boolean);
    begin
      AllowEdit := FCanEditListView;
    end;
    

    【讨论】:

      猜你喜欢
      • 2020-02-06
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 2015-01-24
      • 1970-01-01
      • 2017-06-09
      相关资源
      最近更新 更多