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. 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. 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.Co开发者_如何学Cunt:4" how can i get selectName to just equal the header of the selected treeView item. 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:
string selectName = ((TreeViewItem)(treeView1.SelectedItem)).Header.ToString();
hope that's what you needed!
精彩评论