RadGridView添加序号列
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) + 1).ToString(); return textBlock; } }
<telerik:RadGridView> <telerik:RadGridView.Columns> <local:RowNumberColumn Width="32" Header="序号"/> </telerik:RadGridView.Columns> </telerik:RadGridView>