[英]How to get Selected Row of WPF Devexpress TreeList in .NET?
我是Devexpress控件的新手。 我已经添加了TreeList
控件,使用实体将其绑定。 我想获取选定的列值,即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? 帮助赞赏! 谢谢!
代码隐藏方式 :
您可以使用以下代码片段,通过TreeListView.GetNodeValue方法获取焦点所在行中包含的指定单元格的值:
要了解更多信息,请参阅获取和设置单元格值 。
<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属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.