treeView_selectedItemChanged 事件处理程序

发布于 2024-11-16 09:50:38 字数 618 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何其悲哀 2024-11-23 09:50:38

在 treeView_selectedItemChanged 事件处理程序中使用以下代码对我来说效果很好:

string selectName = ((TreeViewItem)(treeView1.SelectedItem)).Header.ToString();

希望这就是您所需要的!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文