我有一个ListView类,该类使用ItemSelectionChanged事件来维护自己的所选项目列表。

Clear()似乎未触发ItemSelectionChanged事件外,此方法运行良好。
这意味着在调用Clear()之后,列表仍包含在调用Clear()之前突出显示的所有项目。

我想覆盖Clear()方法,以便自己清除列表,但可以看到它没有被标记为虚拟。有没有其他方法可以使用现有的Clear()方法?

计划B是我只是编写自己的方法,并在清除后立即调用它,但这并不是很好。

listView1.Clear();
listView1.ClearMyList();

最佳答案

实际上我不知道C#的此功能的名称(公共新void),但是您可以通过创建自己的“ customListView”来实现。

var listView = new CustomListView();
listView.Clear();

public class CustomListView : ListView
{
    public new void Clear()
    {
        Console.WriteLine("I can clear myself...");
    }
}


c# - 重写ListView Clear()方法-LMLPHP

07-24 09:48
查看更多