欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

WPF中Datagrid控件添加行号

程序员文章站 2022-03-23 12:44:01
1 /// 2 /// 导入Excel文件按钮 3 /// 4 /// 5 /// 6 private void InputExcelFile_Click(object sender, RoutedEventArgs e) 7 { 8 //将数... ......
 1      /// <summary>
 2         /// 导入excel文件按钮
 3         /// </summary>
 4         /// <param name="sender"></param>
 5         /// <param name="e"></param>
 6         private void inputexcelfile_click(object sender, routedeventargs e)
 7         {
 8             //将数据绑定到datagird控件中
 9             datagridsheet.itemssource = readbynpoi.inputworkbookfromexcel(getexcelfilepath());
10             datagridsheet.headersvisibility = datagridheadersvisibility.row;
11             datagridsheet.rowheaderwidth = 30;
12             //loadingrow事件
13             datagridsheet.loadingrow += datagridsheet_loadingrow;
14         }
15 
16         private void datagridsheet_loadingrow(object sender, datagridroweventargs e)
17         {
18             e.row.header = e.row.getindex() + 1;//递增行号
19         }