如何显示 wpf 工具包数据网格的行索引? [英] How to show row index for wpf toolkit datagrid?

查看:22
本文介绍了如何显示 wpf 工具包数据网格的行索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想在wpf工具包DataGrid中添加一个索引列来显示DataGrid中每个数据的行索引.怎么样?

I just want to add a index column in wpf toolkit DataGrid to show row index of each data in the DataGrid. How?

<dg:DataGrid ItemsSource="{Binding List}"                              
             SelectionMode="Extended"
             IsReadOnly="True"
             AutoGenerateColumns="False"
             HorizontalAlignment="Left">
    <dg:DataGrid.Columns>

        **<dg:DataGridTextColumn Header="Row Index"></dg:DataGridTextColumn>**
        <dg:DataGridTextColumn Header="Branch"
                               Binding="{Binding Branch.Id}"></dg:DataGridTextColumn>
        <dg:DataGridTextColumn Header="Count"
                               Binding="{Binding RequestCount}"></dg:DataGridTextColumn>
    </dg:DataGrid.Columns>
</dg:DataGrid>

推荐答案

您可以使用多重绑定和转换器绑定到行中的项目和父数据网格.然后在转换器中查找数据网格项中行的位置.

you can use a multibinding and a converter to bind to the item in the row and the parent datagrid. then in the converter you look up the position of the row in the datagrids items.

此页面上下载示例 WPFDatagridWithRowNumbers.zip

On this page download the sample WPFDatagridWithRowNumbers.zip

享受吧!

这篇关于如何显示 wpf 工具包数据网格的行索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆