Hello All,
I'm new in VB.NET and can't seem to figure out how listbox iteration works.
Here's the code:
1 Private Sub ResetPlacement()
2 Dim strSelectedSubject As String
3 Dim dr As DataRow
4 Dim i As Int32
5
6 lbxSubjects.ClearSelected()
7
8 For i = 0 To lbxSubjects.Items.Count - 1
9 strSelectedSubject = lbxSubjects.Items(i).ToString
10
11 For Each dr In dtCurriculumSubject.Rows
12 If strSelectedSubject.Trim = _
13 dr("SubjectName").ToString.Trim Then
14 dr("Placement") = i + 1
15 Exit For
16 End If
17 Next
18 Next
19 End Sub
Everytime I iterate throught the FOR loop in line 8, I get a different 'strSelectedSubject' result in line 9. These are the results:
i Value Result Remarks
------- ------ -------
0 "Latin 1" This is correct
1 "System.Data.DataRowView" ???
2 "System.Data.DataRowView" ???
I tried using the following syntax with same result:
lbxSubjects.GetItemText(lbxSubjects.items(i))
I also tried the following but it gives an error on "late-Binding" with is not permitted when OPTION STRICT is ON:
lbxSubjects.items(i).Text
lbxSubjects.items(i).Value
Please enlighten me!!!
God bless,
Balarao
I'm new in VB.NET and can't seem to figure out how listbox iteration works.
Here's the code:
1 Private Sub ResetPlacement()
2 Dim strSelectedSubject As String
3 Dim dr As DataRow
4 Dim i As Int32
5
6 lbxSubjects.ClearSelected()
7
8 For i = 0 To lbxSubjects.Items.Count - 1
9 strSelectedSubject = lbxSubjects.Items(i).ToString
10
11 For Each dr In dtCurriculumSubject.Rows
12 If strSelectedSubject.Trim = _
13 dr("SubjectName").ToString.Trim Then
14 dr("Placement") = i + 1
15 Exit For
16 End If
17 Next
18 Next
19 End Sub
Everytime I iterate throught the FOR loop in line 8, I get a different 'strSelectedSubject' result in line 9. These are the results:
i Value Result Remarks
------- ------ -------
0 "Latin 1" This is correct
1 "System.Data.DataRowView" ???
2 "System.Data.DataRowView" ???
I tried using the following syntax with same result:
lbxSubjects.GetItemText(lbxSubjects.items(i))
I also tried the following but it gives an error on "late-Binding" with is not permitted when OPTION STRICT is ON:
lbxSubjects.items(i).Text
lbxSubjects.items(i).Value
Please enlighten me!!!
God bless,
Balarao