01.
Private
Sub
Form1_Load(sender
As
System.
Object
, e
As
System.EventArgs)
Handles
MyBase
.Load
02.
03.
04.
05.
Dim
dtTable
As
DataTable =
New
DataTable(
"myTable"
)
06.
07.
dtTable.Columns.Add(
New
DataColumn(
"ColID"
,
GetType
(
Integer
)))
08.
dtTable.Columns.Add(
New
DataColumn(
"ColFullName"
,
GetType
(
String
)))
09.
dtTable.Columns.Add(
New
DataColumn(
"ColPoint"
,
GetType
(
Integer
)))
10.
dtTable.Columns.Add(
New
DataColumn(
"ColCountryCode"
,
GetType
(
String
)))
11.
12.
dtTable.Rows.Add(1,
"Weerachai Nukitram"
, 10,
"TH"
)
13.
dtTable.Rows.Add(2,
"Wisarut Nukitram"
, 20,
"US"
)
14.
dtTable.Rows.Add(3,
"Wipa Nukitram"
, 30,
"TH"
)
15.
16.
17.
18.
Dim
dtCountry
As
DataTable =
New
DataTable(
"myCountry"
)
19.
dtCountry.Columns.Add(
New
DataColumn(
"ColCountryCode"
,
GetType
(
String
)))
20.
dtCountry.Columns.Add(
New
DataColumn(
"ColCountryName"
,
GetType
(
String
)))
21.
22.
dtCountry.Rows.Add(
"TH"
,
"Thailand"
)
23.
dtCountry.Rows.Add(
"US"
,
"United States"
)
24.
25.
26.
Me
.myDataGridView.AutoGenerateColumns =
False
27.
Me
.myDataGridView.AllowUserToAddRows =
False
28.
Me
.myDataGridView.DataSource = dtTable
29.
30.
31.
Me
.COUNTRY.DataPropertyName =
"Name"
32.
Me
.COUNTRY.DataSource = dtCountry
33.
Me
.COUNTRY.ValueMember =
"ColCountryCode"
34.
Me
.COUNTRY.DisplayMember =
"ColCountryName"
35.
36.
37.
For
Each
row
As
DataGridViewRow
In
Me
.myDataGridView.Rows
38.
Dim
sel
As
DataRow = dtTable.
Select
(
"ColID = '"
& row.Cells(
"ID"
).Value &
"' "
).FirstOrDefault()
39.
If
Not
(IsNothing(sel))
Then
40.
row.Cells(
"COUNTRY"
).Value = sel.Item(
"ColCountryCode"
)
41.
End
If
42.
Next
43.
44.
45.
Dim
iTotal
As
Integer
46.
For
Each
row
As
DataGridViewRow
In
Me
.myDataGridView.Rows
47.
iTotal = iTotal + row.Cells(
"POINT"
).Value
48.
Next
49.
Me
.lblTotalPoint.Text =
String
.Format(
"Total Point : {0}"
, iTotal)
50.
51.
End
Sub