【发布时间】:2014-07-06 19:56:56
【问题描述】:
我想在单击 TListView 选定项目时禁用进入编辑模式,但不完全禁用它(设置属性 ReadOnly=True)。我希望仍然能够通过其他方法对其进行编辑。有可能吗?
【问题讨论】:
标签: delphi edit delphi-6 tlistview
我想在单击 TListView 选定项目时禁用进入编辑模式,但不完全禁用它(设置属性 ReadOnly=True)。我希望仍然能够通过其他方法对其进行编辑。有可能吗?
【问题讨论】:
标签: delphi edit delphi-6 tlistview
我没有看到任何简单的方法来准确检测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;
【讨论】: