listviews / multiple forms / select case - HELP!!

russgreen

Freshman
Joined
Feb 6, 2003
Messages
27
Location
UK
I have a mutli form db app. The main form uses multiple listview to display data. Double clicking on an item in a listview opens another form with more detailed information relating to that item (a bit like in an address book app). On closing the second form I want the listview in the first form to refresh. I have a sub using Select Case to refresh only the list view that contains the item that has been opened but I'm having trouble passing the listviewname to it. The two subs I'm having trouble with are below, can anyone see any glaring errors with them? The RefreshListView(<bla bla>) routine are not being called from FillList()

THIS SUB IS CALLED WHEN THE USER DOUBLE CLICKS AN ITEM TO OPEN THE NEW FORM...

Visual Basic:
    Private Sub OpenSelected(ByVal listviewname, ByVal DataTable, ByVal DataID, ByVal FormTitle)
        On Error Resume Next
        Dim x As Long
        x = listviewname.Items(0).Text

        Dim frm As New frmContactDet()
        With frm
            'Here we are going to Open the Dataset for the Item
            Dim ds As New DataSet()
            Dim da As OleDbDataAdapter = New OleDbDataAdapter()

            'Declare and Open OLEDBCONNECTION FOR Access2k database
            Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dbFullPath)
            conn.Open()

            da.SelectCommand = New OleDbCommand("SELECT * FROM " & DataTable & " WHERE " & DataID & "=" & CLng(listviewname.SelectedItems(0).Tag), conn)
            da.Fill(ds)
            Dim dr As DataRow

            'Now we have the Record - Hopefully
            If ds.Tables(0).Rows.Count > 0 Then
                dr = ds.Tables(0).Rows(0)
                .lngContactID = dr(DataID)
            End If

            .MyTitle = FormTitle
            .strDataTable = DataTable
            .strContactID = DataID

            dr = Nothing
            da.Dispose()
            ds.Dispose()
            conn.Close()
            .ShowDialog(Me)

            'THIS SHOULD REFRESH THE ORIGINATING LISTVIEW BUT DOESN'T
            'WHEN FILLALLLISTS() GETS CALLED HERE INSTEAD EVERYTHING WORKS OK
            FillList(listviewname)

        End With
    End Sub

Visual Basic:
    Private Sub FillList(ByVal listview)
        Select Case listview
            Case lvwProjectsActive
                RefreshProjectsActive()
            Case lvwProjectsClosed
                RefreshProjectsClosed()
            Case lvwClientPvt
                RefreshClientPvt()
            Case lvwClientCorp
                RefreshListView(Me.lvwClientCorp, "ClientCorp", "ClientCorpID")
            Case lvwArchitect
                RefreshListView(Me.lvwArchitect, "Architect", "ArchitectID")
            Case lvwLandArch
                RefreshListView(Me.lvwLandArch, "LandArch", "LandArchID")
            Case lvwStrucEng
                RefreshListView(Me.lvwStrucEng, "StrucEng", "StrucEngID")
            Case lvwServEng
                RefreshListView(Me.lvwServEng, "ServEng", "ServEngID")
            Case lvwQuantSurv
                RefreshListView(Me.lvwQuantSurv, "QuantSurv", "QuantSurvID")
            Case lvwProjMan
                RefreshListView(Me.lvwProjMan, "ProjMan", "ProjManID")
            Case lvwContractor
                RefreshListView(Me.lvwContractor, "Contractor", "ContractorID")
        End Select
End Sub

Visual Basic:
    Private Sub FillAllLists()
        'fill list boxes from database
        RefreshProjectsActive()
        RefreshProjectsClosed()
        RefreshClientPvt()

        RefreshListView(Me.lvwClientCorp, "ClientCorp", "ClientCorpID")
        RefreshListView(Me.lvwArchitect, "Architect", "ArchitectID")
        RefreshListView(Me.lvwLandArch, "LandArch", "LandArchID")
        RefreshListView(Me.lvwStrucEng, "StrucEng", "StrucEngID")
        RefreshListView(Me.lvwServEng, "ServEng", "ServEngID")
        RefreshListView(Me.lvwQuantSurv, "QuantSurv", "QuantSurvID")
        RefreshListView(Me.lvwProjMan, "ProjMan", "ProjManID")
        RefreshListView(Me.lvwContractor, "Contractor", "ContractorID")
    End Sub

Regards,
Russ

http://www.russgreen.net/software/
 
I can't believe you're not specifying parameter types on your functions. You should _always_ specify variable types, when declaring and when defining parameters. When you don't force strict strong-typing, you get errors like this one which are hard to trace.

Go in to Project Properties and turn on Option Strict, that will force you to do this properly. Once it's on you should discover the cause of the error.
 
listviewname

EDIT: Just rechecked your code, and the problem is not the string! You are passing listview to FillList BYVAL and not BYREF so when you compare it to lvwProjectsActive they are NOT the same. Change ByVal to ByRef in FillList and you should have no problem

I agree, Strong Typing is ESSENTIAL!

Now, here is my question: Is listviewname a String containing the name of the listview, or an actual listview object (This is impossible to tell, without seing code that calls OpenSelected because you have not used strong typing)

If listview name is a ListView object, there should be no problems, you are having some other issue

If listview name is a String containg the name, the problem is obvious. You are trying to compare the String "lvwProjectsActive" (for example) with the object itself! You must change your Select Case so that instead of saying:
Code:
Case lvwProjectsActive
you should say:
Code:
Case "lvwProjectsActive"
or
Code:
Case lvwProjectsActive.Name

Judging by the name, I think listviewname is the latter, but PLEASE give types to your variables!
For example:
Code:
ByVal listviewname as String
 
A listview will be passed by reference no matter if the parameter is declared byval or byref.
 
lisviewname is a listview object. I have taken the advice and forced strong typing. after spending all day sorting out errors in my code it all worked and i was able to debug fully before CaNaDiAn BaCoN posted an answer (thanks Devil).

Actually, I have to say I started this project when i was a complete novice and most of the syntax problems i was getting early on were beyond my understanding of the language and so i followed someones advice and switched option explicit to off (at the time i thaught it was great cause my code worked).

I was really suprised today as i switched option explicit on and i basically had to recode most of the functions and subs in my app but i was able to do it without even looking anything up. thanks guys for your help and putting me straight on Strong Typing

Russ
 
Back
Top