如何显示wpf toolkit datagrid的行索引? [英] How to show row index for wpf toolkit datagrid?

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

问题描述

我只想在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>


推荐答案

可以使用多字段和转换器绑定行和父数据网格中的项目。那么在转换器中,您可以查看datagrids项中行的位置。

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 toolkit datagrid的行索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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