如何使用TreeListView加速交互/绘图

时间:2013-11-16 01:01:20

标签: c# performance objectlistview treelistview

我正在尝试使用此开源软件包(http://objectlistview.sourceforge.net/cs/index.html)中的TreeListView。我编写的代码构建了TreeListView,但是绘制项目的速度很慢,点击时速度很慢。

我的数据模型由父文档和子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的示例项目在我的机器上工作得非常快,所以它显然是我的代码。)

感谢。

0 个答案:

没有答案
相关问题