猿问

c# 在树视图后面创建一个 ID

如何在树视图后面添加 ID?代码:


string players = "Name:Peter ID:1 Name:karl ID:2 Name:max ID:3 Name:Nils ID:4";

var user = players.split().Where(a => a.StartWith("Name:")).ToList();

var ID = players.split().Where(a => a.StartWith("ID:")).ToList();

for(int i= 0; i<user.Count(); i++) {

    var pl = user[i].Substring(user[i].IndexOf(":") + 1);

    var plid = ID[i].Substring(ID[i].IndexOf(":") + 1);

    treeView1.Nodes.Add(pl);

}

现在,如果选择用户,我想在文本框中显示 ID


编辑:我试过了


treeView1.Tag = plid;

但这不起作用..


DIEA
浏览 176回答 1
1回答

手掌心

考虑这个模式:for(int i= 0; i<user.Count(); i++) {&nbsp; &nbsp; TreeNode tn = new TreeNode();&nbsp; &nbsp; tn.Text = "The name";&nbsp; &nbsp; tn.Tag = "The ID";&nbsp; &nbsp; treeView1.Nodes.Add(tn);}
随时随地看视频慕课网APP
我要回答