2013-05-13 57 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

相關問題