RadGridView添加序号列

时间:2023-12-29 11:21:14
    public class RowNumberColumn : GridViewDataColumn
{
public override System.Windows.FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
{
TextBlock textBlock = cell.Content as TextBlock; if (textBlock == null)
{
textBlock = new TextBlock();
} //textBlock.Text = (this.DataControl.Items.IndexOf(dataItem) + 1).ToString();
textBlock.Text = ((this.DataControl.ItemsSource as IList).IndexOf(dataItem) + ).ToString(); return textBlock;
}
}
<telerik:RadGridView>
<telerik:RadGridView.Columns>
<local:RowNumberColumn Width="32" Header="序号"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>