WPF中Datagrid控制元件新增行號

若青若墨發表於2019-01-07
 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         }

 

相關文章