Late binding arraylist issue

E

Earl

Anyone know how to get rid of this late binding issue? SalutationList is a
listarray of all salutation objects from a lookup table.

Dim a As Int32 = SalutationList.Count
For a = 0 To a - 1
If IsDBNull(dv.Item(0).Item("SalutationID")) = False Then
'this is the latebinding problem
If dv.Item(0).Item("SalutationID") =
CInt(SalutationList.Item(a).SalutationID) Then
cmbSal.Text = CStr(SalutationList.Item(a).Salutation)
End If
Else : cmbSal.Text = ""
End If
Next
 
G

Guest

Earl said:
Anyone know how to get rid of this late binding issue? SalutationList is a
listarray of all salutation objects from a lookup table.

Dim a As Int32 = SalutationList.Count
For a = 0 To a - 1
If IsDBNull(dv.Item(0).Item("SalutationID")) = False Then
'this is the latebinding problem
If dv.Item(0).Item("SalutationID") =
CInt(SalutationList.Item(a).SalutationID) Then
cmbSal.Text = CStr(SalutationList.Item(a).Salutation)
End If
Else : cmbSal.Text = ""
End If
Next

If Cint(dv.Item(0).Item("SalutationID")) =
CInt(SalutationList.Item(a).SalutationID) Then
 
C

Cor Ligthert [MVP]

Earl,

Did you try

If CInt(dv.Item(0).Item("SalutationID")) =
CInt(SalutationList.Item(a).SalutationID) Then

I hope this helps,

Cor
 
B

Branco Medeiros

Earl said:
Anyone know how to get rid of this late binding issue? SalutationList is a
listarray of all salutation objects from a lookup table.

'this is the latebinding problem
If dv.Item(0).Item("SalutationID") =
CInt(SalutationList.Item(a).SalutationID) Then
cmbSal.Text = CStr(SalutationList.Item(a).Salutation)
<snip>

How is SalutationList declared? What kind of objects it contains?

If you're using Net 2.0, then you could use generics to specialize
SalutationList; otherwise, you must cast the reference to the
appropriate type before using one of its methods.

That is, supposing the type of object contained in SalutationList is
Salutation:

If dv.Item(0).Item("SalutationID") = _
CType(SalutationList.Item(a), Salutation).SalutationID Then
cmbSal.Text = CType(SalutationList.Item(a), Salutation).Salutation

or, more concisely (if there's such word):

Dim Sal As Salutation = CType(Salutation.Item(a), Salutation)
If dv.Item(0).Item("SalutationID) = Sal.SalutationID Then
cmbSal.Text = Sal.Salutation
...

HTH.

Regards,

Branco.
 
E

Earl

Thanks Branco. I was handling the object incorrectly on the right side of
the equality. Your solution works so long as I also cast the left side to an
integer:

If CInt(dv.Item(0).Item("SalutationID")) = CType(SalutationList.Item(a),
Salutation).SalutationID Then
cmbSal.Text = CType(SalutationList.Item(a), Salutation).Salutation

Yes, "concisely" is a the word.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top