【问题标题】:wpf treeview get selected valuewpf treeview 获取选定值
【发布时间】:2013-05-13 15:54:41
【问题描述】:

我有一个TreeView 和一个ListBox。它们都来自不同的DataTables。

Treeview 从以下位置获取数据:

 DataTable product_type = new DataTable();
 product_type.Columns.Add(new DataColumn("id_product_type", typeof(int)));
 product_type.Columns.Add(new DataColumn("name", typeof(string)));
 product_type.Columns.Add(new DataColumn("id_parent",typeof(int)));
 DS.Tables.Add(product_type);

父子关系:

DS.Relations.Add(new DataRelation("rsParentChild", product_type.Columns["id_product_type"], product_type.Columns["id_parent"]));

所以我想从 SelectedItemChanged 上的 TreeView 中获取 id_product_type 并将其传递给我的列表框,但我如何获得实际值,即 int? p>

【问题讨论】:

  • 能否提供xaml来创建示例项目?

标签: wpf treeview datarowview


【解决方案1】:

这就是你要找的(我使用数据视图绑定列表):

private void tlstView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            int new_value =(int)((DataRowView)e.NewValue).Row["id_product_type"];
        }

【讨论】:

    猜你喜欢
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    • 2011-08-23
    • 2015-10-12
    • 1970-01-01
    相关资源
    最近更新 更多