01.
02.
03.
Public
Class
F14ShowRowIndex
04.
Private
dt
As
New
DataTable
05.
06.
Private
Sub
Form32_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
07.
dt.Columns.Add(
"ItmeName"
,
GetType
(System.
String
))
08.
For
i
As
Integer
= 0
To
10
09.
Dim
dr
As
DataRow = dt.NewRow
10.
dr(0) =
"บรรทัดที่ "
& i
11.
dt.Rows.Add(dr)
12.
Next
13.
Dim
ColA
As
New
DataGridViewTextBoxColumn
14.
With
ColA
15.
.
ReadOnly
=
True
16.
.Name =
"Index"
17.
End
With
18.
19.
Dim
ColB
As
New
DataGridViewTextBoxColumn
20.
With
ColB
21.
.DataPropertyName =
"ItmeName"
22.
.Name =
"ItmeName"
23.
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
24.
End
With
25.
26.
With
dg1
27.
.AutoGenerateColumns =
False
28.
.Columns.AddRange(
New
DataGridViewColumn() {ColA, ColB})
29.
.DataSource = dt
30.
End
With
31.
32.
End
Sub
33.
34.
Private
Sub
dg_RowPostPaint(
ByVal
sender
As
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewRowPostPaintEventArgs) _
35.
Handles
dg1.RowPostPaint
36.
37.
Using b
As
SolidBrush =
New
SolidBrush(dg1.RowHeadersDefaultCellStyle.ForeColor)
38.
e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), _
39.
sender.DefaultCellStyle.Font, _
40.
b, _
41.
e.RowBounds.Location.X + 40, _
42.
e.RowBounds.Location.Y + 3, _
43.
New
StringFormat(StringFormatFlags.DirectionRightToLeft))
44.
End
Using
45.
Me
.dg1(
"Index"
, e.RowIndex).Value = e.RowIndex
46.
End
Sub
47.
48.
End
Class