1

我正在尝试使用这个开源包(http://objectlistview.sourceforge.net/cs/index.html)中的 TreeListView 。我编写的代码可以很好地构建 TreeListView,但是绘制项目很慢,点击时也很慢。

我的数据模型由父 Documents 和子 DocumentVersions 组成(我使用的是复合设计模式,这就是下面 ProjectComponent 类的原因。每个 Document 可以有任意数量的 DocumentVersions;一个 DocumentVersion 不能有任何子类。这是我的类(为简洁起见,我删除了大多数不相关的代码):

abstract public class ProjectComponent
{
    public abstract bool HasChildren { get; }
    public int ID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

public class Document : ProjectComponent
{
    public virtual List<DocumentVersion> DocumentVersions { get; set; }
    public override bool HasChildren
    {
        get { if (this.DocumentVersions.Count > 0) return true; else return false;}
    }
}

public class DocumentVersion : ProjectComponent
{
    public int VersionNo { get; set; }
    public DocumentType Type { get; set; }
    public string Filename { get; set; }
    [ForeignKey("Document")]
    public int DocumentID { get; set; }
    public Document Document { get; set; }
    public override bool HasChildren
    {
        get { return false; }
    }
}

为了构建 TreeListView,我将所有文档拉到一个列表 (CurrentDocumentList) 中,然后按如下方式构建树:

    void InitializeTV2(TreeListView tlv)
    {
        tlv.HideSelection = false;
        tlv.CanExpandGetter = delegate(object x)
        {
            return ((ProjectComponent)x).HasChildren;
        };
        tlv.ChildrenGetter = delegate(object x) { return ((Document)x).DocumentVersions; };
        tlv.Roots = CurrentDocumentList;
    }

结果是一个准确的 TreeListView,但它的响应速度不是很快(展开时绘制速度很慢,点击时速度很慢)。CanExpandGetter 经常被击中,但根据文档,这是正常行为。

如果有人对我如何加快速度有任何提示,我将不胜感激。(使用包附带的 FileSystemInfo 的示例项目在我的机器上运行得非常快,所以它显然是我的代码)。

谢谢。

4

0 回答 0