I seem to have broken something I get this error

Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.KeyPressEventArgs'.

my code:

Private Sub ListControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListControl.SelectedIndexChanged
        Dim connString As String = My.Settings.strConn
        Dim conn As New SqlConnection(connString)
        If ListControl.SelectedIndex > -1 Then
            Dim tenants As Tenant = ListControl.SelectedItem

            TextBoxTenantIdUp.Text = tenants.ID
            TextBoxTenantFirstNameUp.Text = tenants.FirstName
            TextBoxTenantLastNameUp.Text = tenants.LastName
            TextBoxPhoneUp.Text = tenants.phone
            DateTimePickerDobUp.Value = tenants.Dob
            MaskedEditBoxEmailUp.Text = tenants.Email
            TextBoxNotesUp.Text = tenants.Notes
            TextBoxPropRefUp.Text = tenants.PropertyC
            TextBoxPhoneUp.Enabled = True
            MaskedEditBoxEmailUp.Enabled = True
            TextBoxNotesUp.Enabled = True

            Try
                conn.Open()
                Dim qry As String = "select * from property where propRef='" + TextBoxPropRefUp.Text + "'"

                Dim cmd As New SqlCommand(qry, conn)

                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.Read() Then
                    TextBoxHouseNoCur.Text = dr(3)
                    TextBoxStreetCur.Text = dr(4)
                    TextBoxCityCur.Text = dr(5)
                    TextBoxPostCodeCur.Text = dr(6)
                    TextBoxRentCur.Text = dr(12)
                End If
                dr.Close()
            Catch ex As Exception

            Finally

                conn.Dispose()
                conn.Close()
            End Try
        End If
    End Sub

it fails on TextBoxPropRefUp.Text = tenants.PropertyC

this is my Tenant Class

Public Class Tenant
        Private _t_id As String
        Private _firstName As String
        Private _lastName As String
        Private _email As String
        Private _phone As Decimal
        Private _Dob As String
        Private _property As String
        Private _notes As String
        Private _existing As Boolean

        Public Property ID() As String
            Get
                Return _t_id
            End Get
            Set(ByVal value As String)
                _t_id = value
            End Set
        End Property

        Public Property FirstName() As String
            Get
                Return _firstName
            End Get
            Set(ByVal value As String)
                _firstName = value
            End Set
        End Property

        Public Property LastName() As String
            Get
                Return _lastName
            End Get
            Set(ByVal value As String)
                _lastName = value
            End Set
        End Property

        Public Property Email() As String
            Get
                Return _email
            End Get
            Set(ByVal value As String)
                _email = value
            End Set
        End Property

        Public Property phone() As Long
            Get
                Return _phone
            End Get
            Set(ByVal value As Long)
                _phone = value
            End Set
        End Property

        Public Property PropertyC() As String
            Get
                Return _property
            End Get
            Set(ByVal value As String)
                _property = value
            End Set
        End Property

        Public Property Notes() As String
            Get
                Return _notes
            End Get
            Set(ByVal value As String)
                _notes = value
            End Set
        End Property

        Public Property Dob() As String
            Get
                Return _Dob
            End Get
            Set(ByVal value As String)
                _Dob = value
            End Set
        End Property

        Public ReadOnly Property Name() As String
            Get
                Return LastName & ", " & FirstName
            End Get
        End Property

        Public Property Existing() As Boolean
            Get
                Return _existing
            End Get
            Set(ByVal value As Boolean)
                _existing = value
            End Set
        End Property

    End Class

    Private tenants As New List(Of Tenant)

Any idea why this has stopped working? I notice some of my event handlers had also disappeared so I had re added them could this be my problem?

thanks

M

I went back to an older version :-(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.