treeView_selectedItemChanged 事件处理程序
我有一个 wpf c# 应用程序,它从文本文件中获取家务的名称,然后加载到多个列表中,例如 nameOfChore 列表、ChorePriority 列表,然后当我选择一个时将列表加载到树视图中在树视图中的任务/杂务中,我试图让它将给定杂务的列表数据加载到右侧的文本框中。我有一个 for 循环检查 treeView 所选项目是否等于任何杂务名称,如果是,则加载文本框。问题在于 selectName 变量,它应该加载杂务名称,例如“Cut Grass”,但它加载的是“System.Windows.Controls.TreeViewItem Header:Cut Grass Items.Count:4”,我如何获得 selectName正好等于所选树视图项目的标题。谢谢。
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])
{
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.Count: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])
{
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 treeView_selectedItemChanged 事件处理程序中使用以下代码对我来说效果很好:
希望这就是您所需要的!
in treeView_selectedItemChanged event handler use following code works fine for me:
hope that's what you needed!