3

In Delphi XE4 if you set HideSelection to true and use an explorer style TListView (when the selection rectangle has a gradient background like Windows Explorer) clicking on another control will not hide the selection rectangle. 它会呆在那里,就好像什么都没发生一样——当 Listview 没有焦点时,它甚至不会像往常一样变成灰色矩形。

这是 Delphi 错误还是 MS Listview 控件的“功能”?是否有任何已知的解决方法或修复方法?真的很烦...

4

2 回答 2

4

这是底层控件的一个特性LVS_SHOWSELALWAYS除了将列表视图样式传递给底层控件之外,delphi 代码对该属性没有任何作用。

起初我对你的问题感到惊讶。我从未见过你描述的行为。经过仔细检查,我意识到这是因为我所有的列表视图都是虚拟的。也就是说,他们设置OwnerDataTrue提供内容以响应OnData事件。这样做是我所知道的唯一解决方法。

于 2014-06-03T15:45:46.073 回答
1

David 解释了这个“功能”,这里有一个解决方法。

通过利用OnExit事件保存选择并将选择设置为零,您将模仿所需的行为。当ListView聚焦时,恢复选择。要使其对鼠标做出反应,请将ListView焦点放在OnMouseEnter事件中。

Type
  TForm1 = class(TForm)
  ...
  private
    FSelected: TListItem;
  ...
  end;

procedure TForm1.ListView1Enter(Sender: TObject);
begin
  if (ListView1.SelCount = 0) and Assigned(FSelected) then
    ListView1.Selected := FSelected;
end;

procedure TForm1.ListView1Exit(Sender: TObject);
begin
  FSelected := ListView1.Selected;
  if Assigned(FSelected) then ListView1.Selected := Nil;
end;

procedure TForm1.ListView1MouseEnter(Sender: TObject);
begin
  ListView1.SetFocus;
end;

提到了这个解决方案,为什么不选择简单的 set HideSelection = false,当没有焦点时,选定的项目会变成灰色,就像评论中提到的 Sertac 一样。

于 2014-06-04T05:00:29.233 回答