Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listview

Status
Not open for further replies.

brews

Technical User
Dec 12, 2007
194
US
Have a list view that populates members from an Access DB. Purpose is then to populate a form when a members name is clicked:

Code:
Private Sub mnuView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuView.Click
        Dim frm As New frmAllView
        tsStatus.Text = ""
        FormChange(bFormChanged)
        Me.Hide()
        If Not dataMgr.MTDatabase Then
            MessageBox.Show("Enter a record to continue", "No records")
            Me.Show()
        Else
            [highlight #EDD400]frm.ShowDialog() ' this throws an exception[/highlight]
                 [indent][/indent][img]https://res.cloudinary.com/engineering-com/image/upload/v1484996610/tips/exception_vqynag.jpg[/img]
            If frm.lvwDisplay.SelectedIndices.Count = 0 Then
                Exit Sub
            Else
                iID = CInt(frm.lvwDisplay.SelectedItems(0).Index)
                NoRecords()
                dataMgr.FindOneName(iID, nc)
                FillBoxes()

            End If
            Select Case frm.Action
                Case Is = CStr(iID)
                    If frmAllView.lvwDisplay.Items.Count = 0 Then
                        Exit Sub
                    Else
                        iID = CInt(frmAllView.lvwDisplay.SelectedItems(0).Text)
                        dataMgr.FindOneName(iID, nc)
                        FillBoxes()
                        txtLastName.Focus()
                    End If
                Case Is = "X"
                    MsgBox("X")
            End Select
        End If
        txtFirstName.Focus()
        bFormChanged = False
        FormChange(bFormChanged)
    End Sub

Any ideas would be helpful. Thank you.
 

Is there code in the New() method of frmAllView, or in the Form_Load event handler?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
This from _load:

Code:
   Private Sub frmAllView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim nc As New cCustomers
        Dim dataMgr As New cData
        Dim sKey As String = ""
        Dim sName As String = ""
        Dim sCityStZip As String = ""
        Dim sPhone As String = ""
        Dim sDatePd As String = ""
        lv = dataMgr.DisplayAll(lv)
        With lvwDisplay
            .Show()
            .Items.Clear()
            .Columns.Add("ID", 0)
            .Columns.Add("Acct#", 50)
            .Columns.Add("Name", 200)
            .Columns.Add("Address", 210)
            .Columns.Add("City, State Zip", 140)
            .Columns.Add("Telephone", 150)
            .Columns.Add("Date Pd", 80, HorizontalAlignment.Center)
            .Columns.Add("Amt Pd", 70, HorizontalAlignment.Right)
            .Refresh()
            .View = View.Details
            .Width = 925
            .Height = 950
        End With
        With Me
            .Text = "Click Record to edit"
            .Top = 25
            .Width = 950
            Height = 1000
            .StartPosition = FormStartPosition.CenterScreen
        End With

        Dim sItem As ListViewItem
        For Each nc In lv
            Dim areaCode As String = ""
            Dim Exchange As String = ""
            Dim sNumber As String = ""
            Dim Phone As String = nc.Phone
            Dim result As String = ""
            If nc.Phone.ToString = "" Then
                sPhone = nc.Phone
            Else
                result = Phone.Substring(1, 3)
                areaCode = Phone.Substring(1, 3)
                areaCode = nc.Phone.Substring(1, 3)
                Exchange = nc.Phone.Substring(5, 3)
                sPhone = areaCode & ")" & Exchange & "-" & sNumber
            End If
            '' ''sKey = Format(nc.CustomerID, "0000")
            sName = Trim(nc.Lastname) & ", " & Trim(nc.Firstname)
            Dim iAmtPd As String = FormatCurrency(nc.AmountPaid, 2)
            Dim sAddress = Trim(nc.StreetNumber) & " " & Trim(nc.Address)
            sCityStZip = Trim(nc.City) & ", " & Trim(nc.State) & " " & Trim(nc.Zip)
            sDatePd = (nc.DatePd)
            sItem = New ListViewItem
            sItem.Text = CStr(sKey)
            sItem.SubItems.Add(nc.AccountNumber)
            sItem.SubItems.Add(sName)
            sItem.SubItems.Add(sAddress)
            sItem.SubItems.Add(sCityStZip)
            sItem.SubItems.Add(Phone)
            sItem.SubItems.Add(sDatePd)
            sItem.SubItems.Add(FormatCurrency(iAmtPd, 2))
            lvwDisplay.Items.Add(sItem)
        Next nc
    End Sub

Is this what you are looking for?
 
Well, nothing there looks like it could be causing the problem. Click the View Detail link on the error message and post that here. Basically we're looking for the place where you try to use a System.EventArgs object in place of a System.Windows.Forms.KeyPressEventArgs object.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Here is the download when clicking view detail:
Code:
[URL unfurl="true"]http://www.classreunionprogram.com/downloads/EPC/invalid%20cast.txt[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top