[英]treeView_selectedItemChanged event handler
I have a wpf c# application that gets the name of household chores from a text file and then loads then into a several lists such as a list of nameOfChore, a list of ChorePriority, and then load the lists into the treeview, when i select one of the tasks/chores in the treeView I am trying to get it to load the list data for the given chore into text boxes on the right. 我有一个wpf c#应用程序,该应用程序从文本文件中获取家务的名称,然后将其加载到几个列表中,例如nameOfChore列表,ChorePriority列表,然后将这些列表加载到treeview中(当我选择一个时) treeView中的任务/琐事中,我想让它将给定杂项的列表数据加载到右侧的文本框中。 I have a for loop checking if the treeView selected item is equal to any of the names of chores, and if it is, it then loads the text box. 我有一个for循环,用于检查treeView所选项目是否等于任何杂项名称,如果是,则将其加载文本框。 The problem is with the selectName variable it should be loaded with the chore name such as "Cut Grass" but instead it gets loaded with "System.Windows.Controls.TreeViewItem Header:Cut Grass Items.Count:4" how can i get selectName to just equal the header of the selected treeView item. 问题是与selectName变量有关,应该使用诸如“剪切草”之类的杂项名称来加载,但是相反,它却要与“ System.Windows.Controls.TreeViewItem标头:剪切草Items.Count:4”一起加载,我该如何获取selectName刚好等于所选treeView项的标题。 Thanks. 谢谢。
for (int i = 0; i < name.Count; ++i) {
//string selectName = treeView1.SelectedItem.ToString(); I have tried this, and it gets the same value
string selectName = treeView1.SelectedValue.ToString();
if (selectName == name[i])
{
in treeView_selectedItemChanged event handler use following code works fine for me: 在treeView_selectedItemChanged事件处理程序中,使用以下代码对我来说效果很好:
string selectName = ((TreeViewItem)(treeView1.SelectedItem)).Header.ToString();
hope that's what you needed! 希望这就是您所需要的!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.