如何在DevExpress WPF TreeListControl中获得焦点或选定的值?

时间:2012-10-10 12:57:27

标签: .net wpf devexpress treelist

我正在使用DevExpress TreeListControl:

void TreeListView_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) {
    string val;
    PropertyInfo[] properties =  e.NewRow.GetType().GetProperties();
    foreach (PropertyInfo item in properties) {
        string x =  item.Name;
        if (x == "Id") {
            var barProperty = item.GetType().GetProperty("Id");
            if (barProperty != null) {
                object[] obj = new Object[0];
                val = item.GetValue(sender, obj) as string;
            }
        }
    }
}

如何获取选定的行值?

1 个答案:

答案 0 :(得分:2)

根本不需要使用反射。您可以使用TreeListView.FocusedNode属性和TreeListView.GetNodeValue方法:

object id = treeListView.GetNodeValue(treeListView.FocusedNode,"Id");