2013-05-13 59 views
0

我是Devexpress控件的新手。我已经使用实体添加了TreeList控件。我想选择的列值即ID如何在.NET中获取选定的WPF Devexpress TreeList行?

在.XAML文件:

<dxg:TreeListControl Name="treeListContacts" ItemsSource="{Binding Data, Source={StaticResource EntityServerModeDataSource2}}" AutoPopulateColumns="True" HorizontalAlignment="Left" Margin="10,19,0,0" VerticalAlignment="Top" Height="317" Width="180" FocusableChanged="treeListContacts_FocusableChanged"> 
      <dxg:TreeListControl.Columns> 
       <dxg:TreeListColumn FieldName="Company_ID" ReadOnly="True" Width="30" Visible="False"/> 
       <dxg:TreeListColumn FieldName="CompanyName" ReadOnly="True"/> 
      </dxg:TreeListControl.Columns> 
      <dxg:TreeListControl.View> 
       <dxg:TreeListView ShowTotalSummary="True"/> 
      </dxg:TreeListControl.View> 
     </dxg:TreeListControl> 

这里,现在我想选择的公司ID? 帮助赞赏!谢谢!

回答

1

代码隐藏方式
您可以获得通过使用下面的代码片段TreeListView.GetNodeValue方法关注的行内包含指定单元格的值:

要了解更多信息,请参阅Obtaining and Setting Cell Values

<dxg:TreeListControl ItemsSource="{Binding Data, Source={StaticResource EntityServerModeDataSource2}}" AutoPopulateColumns="True" HorizontalAlignment="Left" Margin="10,19,0,0" VerticalAlignment="Top" Height="317" Width="180" FocusableChanged="treeListContacts_FocusableChanged"> 
    <dxg:TreeListControl.Columns> 
     <dxg:TreeListColumn FieldName="Company_ID" ReadOnly="True" Width="30" Visible="False"/> 
     <dxg:TreeListColumn FieldName="CompanyName" ReadOnly="True"/> 
    </dxg:TreeListControl.Columns> 
    <dxg:TreeListControl.View> 
     <dxg:TreeListView ShowTotalSummary="True" x:Name="treeListView"/> 
    </dxg:TreeListControl.View> 
</dxg:TreeListControl> 


//... 
object id = treelistView.GetNodeValue(treelistView.FocusedNode, "Company_ID"); 

MVVM方式
您可以在视图模型定义FocusedRow属性,并将其绑定到TreeListView.FocusedRow财产。

+0

对不起@DmitryG我已经在'FocusableChanged'事件中试过这段代码,但它不会工作。错误:不包含'GetNodeValue'的定义:( – 2013-05-13 07:17:20

+0

@SHEKHARSHETE您正在使用的是哪个版本?请确保'x:Name'与treelist视图对齐 – DmitryG 2013-05-13 07:35:55

+0

yes offcourse我正在使用'Name'请参阅标记我使用的是vs2012 ultimate和devexpress 12.2版本,当第一次加载页面时,默认情况下如何防止行重点? – 2013-05-13 07:48:05

相关问题