Late binding confusion

E

Earl

I can bind an arraylist to a combobox without a "late binding" error, but I
cannot get to the value directly. Because?

For example, I create an public arraylist of employee objects in the module
(note the Employee is a separate class with the 4 properties being
assigned). I can then bind that arraylist to a combo AND assign the
EmployeeID as a valuemember to the combo, but can NOT pull that value
directly for a comparison. I'm not sure why or what the error is telling me
about the "late binding" in the second case.

***************************************
Public EmployeeList As New ArrayList

Public Sub PopulateEmployees()
Dim intEmpID As Int32
Dim strEmpFirst As String
Dim strEmpMiddle As String
Dim strEmpLast As String

EmployeeList.Clear()

Dim strEmployees As String = "SELECT * FROM OurPersonnel"
Dim strSQLServer As New SqlConnection(strConnString)

Dim daEmployees As New SqlDataAdapter(strEmployees, strSQLServer)

daEmployees.Fill(dsWinMatrix, "dtEmployees")

Dim EmployeeDataView As New
DataView(dsWinMatrix.Tables("dtEmployees"))
Dim intCounter As Int32 = EmployeeDataView.Count

For intCounter = 0 To intCounter - 1
intEmpID = EmployeeDataView.Item(intCounter).Item("EmployeeID")
strEmpFirst =
EmployeeDataView.Item(intCounter).Item("EmployeeFirstName")
strEmpMiddle =
EmployeeDataView.Item(intCounter).Item("EmployeeMiddleInitial")
strEmpLast =
EmployeeDataView.Item(intCounter).Item("EmployeeLastName")

EmployeeList.Add(New Employee(intEmpID, strEmpFirst,
strEmpMiddle, strEmpLast))
Next
End Sub

......................
'no problems here

cmbEmployee.DisplayMember = ToString()
cmbEmployee.ValueMember = "EmployeeID"
cmbEmployee.DataSource = EmployeeList

....................
'late binding error here with Option Strict ON

If IsDBNull(dsFoundRow("ConfirmEntryEmpID")) = False Then
'error on THIS line
If dsFoundRow("ConfirmEntryEmpID") =
EmployeeList.Item(intCounter).EmployeeID Then
cmbConfirmEmployee.Text = EmployeeList.Item(intCounter).ToString
End If
Else : cmbConfirmEmployee.Text = ""
End If
 
S

Scott M.

Why the loop through a DataView? Why not just bind your listbox directly to
the DataTable?
 
E

Earl

Because I use the datatable values for other lists and combos and do not
want them lockstepping.
 
S

Scott M.

I'm not sure that they would lockstep. Have you tried just binding to the
DataTable? It sure would make the code cleaner. Also, you didn't tell us
where dsFoundRow came from.

Here is some of your code cleaned up a bit:

If Not IsDBNull(dsFoundRow("ConfirmEntryEmpID")) AND _
dsFoundRow("ConfirmEntryEmpID") =
EmployeeList.Item(intCounter).EmployeeID Then
cmbConfirmEmployee.Text = EmployeeList.Item(intCounter).ToString
Else
cmbConfirmEmployee.Text = ""
End If
 
E

Earl

Thanks for the thoughts Scott. While I would agree binding straight to the
datatable would make the code appear cleaner, alas, the dataviews are
necessary. Spent too much time working through those issues in the past,
although I'm open to new ideas. If you bind two combos on the same form to
the same datatable, it seems that you have to use some method of isolation
(such as the dataview) to prevent the lockstep action.

What I've come to realize is that the array and arraylists are the actual
culprits. I've examined all the areas of my code in this app, and all of my
late binding issues arise out of use of the arrays and arraylists. The
arraylists are extremely useful for binding objects to the combos, but there
is apparently something I do not understand about how to get to the object
values directly.

arraylist -> itemnumber of object -> object.property.value does not work
 
C

Cor Ligthert

Hi Earl,

Normaly when you have more comboboxes on one datatable you needs as much
dataviews as comboboxes (when you do not want them to walk synchroon, than
you need the same dataview or just the datatable)

So this would be normaly enough.

dim dvcombo1 as new dataview(dt)
dim dvcombo2 as new dataview(dt)

combo1.datasource = dvcombo1
combo2.datasource = dvcombo2
and than the display and valuemembers

I hope this helps?

Cor
 
E

Earl

Yes, that's the point I was making -- there is no other way to escape the
dataviews if you use 2 combos on the same form. Thanks for the input, but
that was not my question -- I'm only stymied by the array/arraylist
late-binding issues.
 
K

Kevin Yu [MSFT]

Hi Earl,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you are having problem with data
binding on an ArrayList. If there is any misunderstanding, please feel free
to let me know.

Could you give us some more information about dsFoundRow? Because you
didn't mention this object in prev code. And please also show us the
detailed exception message?

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
E

Earl

Thanks for following up Kevin. It will be Tuesday/Wednesday (7/27 or 7/28)
before I get back to this issue.
 

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