快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

宝马娱乐bm1395:Winform Treeview实现排序及图标处理



一、排序

1. 承袭 IComparer

2.treeView1.TreeViewNodeSorter = this;

3. 实现IComparer

public int Compare(object x, object y)

{

TreeNode n1 = x as TreeNode;

TreeNode n2 = y as TreeNode;

if (n1 == null || n2 == null)

{

r宝马娱乐bm1395eturn 0;

}

IUs宝马娱乐bm1395er 宝马娱乐bm1395user1 = n1.Tag as IUser;

IUser user2 = n2.Tag as IUser;

if (user1 == null && user2 == null)

{

return n1.ToolTipText.CompareTo(n2.ToolTipTe宝马娱乐bm1395xt);

//return n1.Text.CompareTo(n2.Text);

}

if (user1 != null && user2 != null)

{

return user1.Name.CompareTo(user2.Name);

}

return user1 == null ? 1 : -1;

}

一、图标

1. 假如是一个自定义的control宝马娱乐bm1395,要天生一个dll,就直接插入图片:

2. 假如想在后面方便换图标,就动态加载:

//load images

imageList1.Images.Add(Image.FromFile("Resource\organization.png"));

imageList1.Images.Add(Image.FromFile("Resource\department.png"));

imageList1.Images.Add(Image.FromFile("Resource\None64.ico"));

imageList1.Images.Add(Image.FromFile("Resource\user.png"));

imageList1.Images.Add(Image.FromFile("Resource\loading.gif"));

treeView1.ImageList = imageList1;

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

您可能还会对下面的文章感兴趣: