我是Devexpress控件的新手。我在表单上添加了TreeList
控件,使用Entity绑定它。我想获得所选的列值,即ID
在.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? 帮助感谢!谢谢!
答案 0 :(得分: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方式:
您可以在ViewModel中定义FocusedRow属性并将其绑定到TreeListView.FocusedRow属性。