Results 1 to 4 of 4

Thread: Need assistance loading objects into ListView

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    79

    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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Need assistance loading objects into ListView

    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Sub LoadSignatureView()
    4.         ClearSignatureView()
    5.         Dim cn As New SqlConnection(MerchantManagerConn)
    6.         Dim dr As SqlDataReader
    7.         Dim cmd As New SqlCommand("SignatureLookup", cn)
    8.         cmd.CommandType = CommandType.StoredProcedure
    9.         Try
    10.             cn.Open()
    11.             dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    12.             Do While dr.Read
    13.                 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))
    14.             Loop
    15.         Catch ex As Exception
    16.  
    17.         End Try
    18.     End Sub
    19.  
    20. End Class
    21.  
    22. Public Class Signature
    23.     Private _signatureID As Integer
    24.     Private _fullName As String
    25.     Private _title As String
    26.     Private _department As String
    27.     Private _phoneNumber As String
    28.     Private _faxNumber As String
    29.     Private _recAddedBy As String
    30.     Private _recAddedDate As Date
    31.  
    32.     Sub New(ByVal ID As Integer, ByVal sName As String, ByVal sTitle As String, _
    33.                         ByVal sDepartment As String, ByVal sPhoneNumber As String, _
    34.                         ByVal sFaxNumber As String, ByVal sRecAddedBy As String, _
    35.                         ByVal sRecAddedDate As Date)
    36.         MyBase.New()
    37.         _signatureID = ID
    38.         _fullName = sName
    39.         _title = sTitle
    40.         _department = sDepartment
    41.         _phoneNumber = sPhoneNumber
    42.         _faxNumber = sFaxNumber
    43.         _recAddedBy = sRecAddedBy
    44.         _recAddedDate = sRecAddedDate
    45.     End Sub
    46.  
    47.     Public ReadOnly Property SignatureID() As Integer
    48.         Get
    49.             Return _signatureID
    50.         End Get
    51.     End Property
    52.  
    53.     Public ReadOnly Property FullName() As String
    54.         Get
    55.             Return _fullName
    56.         End Get
    57.     End Property
    58.  
    59.     Public ReadOnly Property Title() As String
    60.         Get
    61.             Return _title
    62.         End Get
    63.     End Property
    64.  
    65.     Public ReadOnly Property Department() As String
    66.         Get
    67.             Return _department
    68.         End Get
    69.     End Property
    70.  
    71.     Public ReadOnly Property PhoneNumber() As String
    72.         Get
    73.             Return _phoneNumber
    74.         End Get
    75.     End Property
    76.  
    77.     Public ReadOnly Property FaxNumber() As String
    78.         Get
    79.             Return _faxNumber
    80.         End Get
    81.     End Property
    82.  
    83.     Public ReadOnly Property RecAddedBy() As String
    84.         Get
    85.             Return _recAddedBy
    86.         End Get
    87.     End Property
    88.  
    89.     Public ReadOnly Property RecAddedDate() As Date
    90.         Get
    91.             Return _recAddedDate
    92.         End Get
    93.     End Property
    94.  
    95.     Public Function toArray() As String()
    96.         Return New String() {SignatureID.ToString, FullName, Title, Department, PhoneNumber, FaxNumber, RecAddedBy, RecAddedDate.ToString}
    97.     End Function
    98.  
    99. End Class

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    79

    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
  •  



Click Here to Expand Forum to Full Width