|
-
May 27th, 2011, 11:05 AM
#1
Thread Starter
Lively Member
Need assistance loading objects into ListView
Good Morning.
I am a bit confused so hopefully someone has a decent answer. I have created a signature class and I want to populate a ListView with the objects from that class. I get errors on when I try to add the items to the Listview. The error states: Overload Resolution failed because no accessible 'Add' can be called with these arguments. Value of type MerchantManager.Signature cannot be converted to 'String'.
Any assistance would be greatly appreciated.
Code:
Public Class Signature
Private _signatureID As Integer
Private _fullName As String
Private _title As String
Private _department As String
Private _phoneNumber As String
Private _faxNumber As String
Private _recAddedBy As String
Private _recAddedDate As Date
Sub New(ByVal ID As Integer, ByVal sName As String, ByVal sTitle As String, _
ByVal sDepartment As String, ByVal sPhoneNumber As String, _
ByVal sFaxNumber As String, ByVal sRecAddedBy As String, _
ByVal sRecAddedDate As Date)
MyBase.New()
_signatureID = ID
_fullName = sName
_title = sTitle
_department = sDepartment
_phoneNumber = sPhoneNumber
_faxNumber = sFaxNumber
_recAddedBy = sRecAddedBy
_recAddedDate = sRecAddedDate
End Sub
Public ReadOnly Property SignatureID() As Integer
Get
Return _signatureID
End Get
End Property
Public ReadOnly Property FullName() As String
Get
Return _fullName
End Get
End Property
Public ReadOnly Property Title() As String
Get
Return _title
End Get
End Property
Public ReadOnly Property Department() As String
Get
Return _department
End Get
End Property
Public ReadOnly Property PhoneNumber() As String
Get
Return _phoneNumber
End Get
End Property
Public ReadOnly Property FaxNumber() As String
Get
Return _faxNumber
End Get
End Property
Public ReadOnly Property RecAddedBy() As String
Get
Return _recAddedBy
End Get
End Property
Public ReadOnly Property RecAddedDate() As Date
Get
Return _recAddedDate
End Get
End Property
End Class
Sub LoadSignatureView()
ClearSignatureView()
Dim cn As New SqlConnection(MerchantManagerConn)
Dim dr As SqlDataReader
Dim cmd As New SqlCommand("SignatureLookup", cn)
cmd.CommandType = CommandType.StoredProcedure
Try
cn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Do While dr.Read
uxSignatureView.Items.Add(New Signature(CInt(dr("SignatureID")), CStr(dr("FullName")), CStr(dr("Title")), CStr(dr("Department")), CStr(dr("PhoneNumber")), CStr(dr("FaxNumber")), CStr(dr("RecAddedBy")), CDate(dr("RecAddedDate"))))
Loop
Catch ex As Exception
End Try
End Sub
-
May 27th, 2011, 11:40 AM
#2
Re: Need assistance loading objects into ListView
try this:
vb Code:
Public Class Form1
Sub LoadSignatureView()
ClearSignatureView()
Dim cn As New SqlConnection(MerchantManagerConn)
Dim dr As SqlDataReader
Dim cmd As New SqlCommand("SignatureLookup", cn)
cmd.CommandType = CommandType.StoredProcedure
Try
cn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Do While dr.Read
uxSignatureView.Items.Add(New ListViewItem(New Signature(CInt(dr("SignatureID")), CStr(dr("FullName")), CStr(dr("Title")), CStr(dr("Department")), CStr(dr("PhoneNumber")), CStr(dr("FaxNumber")), CStr(dr("RecAddedBy")), CDate(dr("RecAddedDate"))).toarray))
Loop
Catch ex As Exception
End Try
End Sub
End Class
Public Class Signature
Private _signatureID As Integer
Private _fullName As String
Private _title As String
Private _department As String
Private _phoneNumber As String
Private _faxNumber As String
Private _recAddedBy As String
Private _recAddedDate As Date
Sub New(ByVal ID As Integer, ByVal sName As String, ByVal sTitle As String, _
ByVal sDepartment As String, ByVal sPhoneNumber As String, _
ByVal sFaxNumber As String, ByVal sRecAddedBy As String, _
ByVal sRecAddedDate As Date)
MyBase.New()
_signatureID = ID
_fullName = sName
_title = sTitle
_department = sDepartment
_phoneNumber = sPhoneNumber
_faxNumber = sFaxNumber
_recAddedBy = sRecAddedBy
_recAddedDate = sRecAddedDate
End Sub
Public ReadOnly Property SignatureID() As Integer
Get
Return _signatureID
End Get
End Property
Public ReadOnly Property FullName() As String
Get
Return _fullName
End Get
End Property
Public ReadOnly Property Title() As String
Get
Return _title
End Get
End Property
Public ReadOnly Property Department() As String
Get
Return _department
End Get
End Property
Public ReadOnly Property PhoneNumber() As String
Get
Return _phoneNumber
End Get
End Property
Public ReadOnly Property FaxNumber() As String
Get
Return _faxNumber
End Get
End Property
Public ReadOnly Property RecAddedBy() As String
Get
Return _recAddedBy
End Get
End Property
Public ReadOnly Property RecAddedDate() As Date
Get
Return _recAddedDate
End Get
End Property
Public Function toArray() As String()
Return New String() {SignatureID.ToString, FullName, Title, Department, PhoneNumber, FaxNumber, RecAddedBy, RecAddedDate.ToString}
End Function
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 27th, 2011, 11:40 AM
#3
Re: Need assistance loading objects into ListView
right... a list view display text... not objects... so you need to tell it what data elements of the object to use to display ... if you look at the documentation of the Items.Add method of a listview, you'll see that the parameter takes a STRING ... which is the text to display for that item... you're trying to pass to it an object.
-tg
-
May 27th, 2011, 11:45 AM
#4
Thread Starter
Lively Member
Re: Need assistance loading objects into ListView
You guys are awesome!
Just for grins and giggles, I tried the following in the LoadSignaturesView function:
[CODE]
Do While dr.Read
uxSignatureView.Items.Add(New Signature(CInt(dr("SignatureID")), CStr(dr("FullName")), CStr(dr("Title")), CStr(dr("Department")), CStr(dr("PhoneNumber")), CStr(dr("FaxNumber")), CStr(dr("RecAddedBy")), CDate(dr("RecAddedDate"))).ToString)
Loop
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|