【转载】wpf DataGrid自动显示行号
来源:http://www.cnblogs.com/Laro/archive/2011/04/04/2005490.html
将datagrid加入序号的方法,在事件中加入如下代码:
dataGrid.LoadingRow +=new EventHandler<DataGridRowEventArgs>(dataGrid_LoadingRow);
关键代码
//添加行号 publicvoid dataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.Header = e.Row.GetIndex() +1; }