2013-05-18 25 views
0

我有一個TreeView和一個ListBox。他們都從不同的DataTables填充。wpf treeview得到選定的值

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"])); 

所以我想從樹視圖得到的id_product_typeSelectedItemChanged,並把它傳遞給我的列表框,但我如何獲得實際值,int?

+0

可以提供XAML以創建示例項目? –

回答

0

THT的您正在尋找(我使用的數據視圖綁定列表)什麼:

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

你是救世主,男人!非常感謝! – acosta