Hi,
I have the following code in VB6:
After conversion to VB .Net, the code is changed to :
My original ListView control 'lvwListView' has been converted to 'AxComctlLib.AxListView'.
While there is no compilation error,I encountered runtime errors: Unable to cast COM object 'ComctlLib.ListItemClass' to class 'Systems.Windows.Forms.ListViewItem'. Instances of types that represent COM components cannot be cast to types that do not represent COM components;...
Now,anyone can tell me how I can solve this problem?
Thanks to all!
I have the following code in VB6:
VB.NET:
Dim itmCI As ListItem
Do While Not resListview.EOF
Set itmCI = lvwListView.ListItems.Add(, , CStr(resListview!CompanyName))
If IsNull(resListview!CompanyId) Then
itmCI.SubItems(1) = ""
Else
itmCI.SubItems(1) = CStr(resListview!CompanyId)
End If
resListview.MoveNext
Loop
Set resListview = Nothing
VB.NET:
Dim itmCI As New ListViewItem("itmCI", 0)
Do While Not resListview.EOF
itmCI = lvwListView.ListItems.Add( , , CStr(resListview.Fields("CompanyName").Value))
If IsDBNull(resListview.Fields("CompanyId").Value) Then
If itmCI.SubItems.Count > 1 Then
itmCI.SubItems(1).Text = ""
Else
itmCI.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, ""))
End If
Else
If itmCI.SubItems.Count > 1 Then
itmCI.SubItems(1).Text = CStr(resListview.Fields("CompanyId").Value)
Else
itmCI.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, CStr(resListview.Fields("CompanyId").Value)))
End If
End If
resListview.MoveNext()
Loop
While there is no compilation error,I encountered runtime errors: Unable to cast COM object 'ComctlLib.ListItemClass' to class 'Systems.Windows.Forms.ListViewItem'. Instances of types that represent COM components cannot be cast to types that do not represent COM components;...
Now,anyone can tell me how I can solve this problem?
Thanks to all!