' get the row number in leading zero format, ' where the width of the number = the width of the maximum number Dim RowNumWidth As Integer = Me.RowCount.ToString().Length Dim RowNumber As New StringBuilder(RowNumWidth) RowNumber.Append(e.RowIndex + 1) While RowNumber.Length < RowNumWidth RowNumber.Insert(0, " ") End While

' get the size of the row number string Dim Sz As SizeF = e.Graphics.MeasureString(RowNumber.ToString(), Me.Font)

' adjust the width of the column that contains the row header cells If Me.RowHeadersWidth < CInt((Sz.Width + 20)) Then Me.RowHeadersWidth = CInt((Sz.Width + 20)) End If