1 // のDataGridView RowPostPaint生成方法を選択 2 。3 。4 。5 プライベート ボイド dgvStudentList_RowPostPaint(オブジェクトSENDER、DataGridViewRowPostPaintEventArgs E) 。6 { 7 DataGridViewStyle.DgvRowPostPaint(この.dgvStudentList、E) 。8 } 。9 10 11 12である 13である /// <まとめ> 14 /// DataGridViewの行番号を追加するには 15 /// </要約> 16 /// <PARAM NAME = "DGV"> </ PARAM> 17 /// <PARAM NAME = "E"> </ PARAM>を 18 パブリック 静的 ボイドDgvRowPostPaint(のDataGridView DGV、DataGridViewRowPostPaintEventArgs E) 19 { 20は 試す 21 { 22 // 添加行号 23 SolidBrush v_SolidBrush = 新しいSolidBrush(dgv.RowHeadersDefaultCellStyle.ForeColor)を、 24 INT v_LineNo = 0 。 25 v_LineNo = e.RowIndex + 1 。 26 ストリング v_Line = v_LineNo.ToString()。 27 (v_Line、e.InheritedRowStyle.Font、v_SolidBrush、e.RowBounds.Location.X + e.Graphics.DrawString 15、+ e.RowBounds.Location.Y 。5 ); 28 } 29は、 キャッチ(例外EX) 30 { 31である メッセージボックス。ショー(「行番号追加するとき、エラー、エラーメッセージが発生する:」 + ex.Messageを、「操作は失敗」); 32 } 33 }