TreeView 控件选中项变色

网上查了不少,发现都是要设置属性的,可这根本没法设置。

还有一些复杂的办法。

自已想了下,其实可以很简单的实现。

直接改被选中项的innertext。

 

 TreeNode trsender = projectlistbind.SelectedNode;
// 清空所有结点的font
TreeNodeCollection tnc = trsender.Parent.ChildNodes;
foreach (TreeNode tn in tnc)
{
string tntext = tn.Text;
int cobegin;
cobegin = tntext.IndexOf(">");
//包含font 也就是 有颜色
if (cobegin != -1)
{
int coend;
coend = tntext.LastIndexOf("<");

tn.Text = tntext.Substring(cobegin + 1, coend - cobegin - 1);
}
}
//更改选中项的Text;
string text = trsender.Text;
string afterclick = "<font color=\"red\">" + text + "</font>";
trsender.Text = afterclick;

posted @ 2013-05-04 22:48  cclient  阅读(346)  评论(0编辑  收藏  举报