首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vb.net TreeView IComparer

vb.net TreeView IComparer
EN

Stack Overflow用户
提问于 2013-09-13 13:41:49
回答 1查看 390关注 0票数 1

为什么这个不起作用?我在MSDN上发现了一个异常:Unable to cast object of type 'OutlookTemplates.com.NodeSorter' to type 'System.Collections.IComparer'.

代码语言:javascript
复制
Public Class NodeSorter
Implements IComparer(Of Windows.Forms.TreeNode)

Public Function Compare(ByVal x As Windows.Forms.TreeNode, ByVal y As Windows.Forms.TreeNode) _
    As Integer Implements IComparer(Of Windows.Forms.TreeNode).Compare
    Dim tx As Windows.Forms.TreeNode = CType(x, Windows.Forms.TreeNode)
    Dim ty As Windows.Forms.TreeNode = CType(y, Windows.Forms.TreeNode)

    If tx.Text.Length <> ty.Text.Length Then
        Return tx.Text.Length - ty.Text.Length
    End If
    Return String.Compare(tx.Text, ty.Text)

End Function
End Class

....

 tv.TreeViewNodeSorter = New NodeSorter()
 tv.Sort()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-13 13:44:13

您需要实现非泛型IComparer接口。

(因为TreeView早于泛型)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18787873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档