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!

as if loading the listview twice

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
425
IT
why twice fresh?
Code:
 Private Sub APRI_LISTVIEW()

    If Not (RS Is Nothing) Then
        If (RS.State And adStateOpen) = adStateOpen Then RS.Close
        Set RS = Nothing
    End If

    Screen.MousePointer = vbHourglass

    Set RS = New ADODB.Recordset
    RS.CursorLocation = adUseClient
    RS.Open SQL, CON, adOpenForwardOnly, adLockReadOnly
    'RS.Sort = ("DATA DESC, IDTAVOLO")

    RS.MoveFirst
    Erase STRDBROWS()
    STRDBROWS = RS.GetRows()
    RS.Close
    Set RS = Nothing

    With Me.LVTAVOLI

        'LockWindowUpdate .hwnd
        SendMessage .hwnd, WM_SETREDRAW, 0, ByVal 0
        .Sorted = False
        .Visible = False
        .ListItems.Clear
        For K = 0 To UBound(STRDBROWS, 2)

            ID = STRDBROWS(11, K)
            Set ITMX = .ListItems.Add(, , STRDBROWS(0, K))
            'ITMX.SmallIcon = ID
            'TAVOLO
            ITMX.SubItems(1) = STRDBROWS(1, K)
            'IDPIATTO
            ITMX.SubItems(2) = STRDBROWS(2, K)
            'NOME PIATTO
            ITMX.SubItems(3) = STRDBROWS(3, K)
            'REPARTO
            ITMX.SubItems(4) = STRDBROWS(4, K)
            ITMX.ListSubItems(4).ReportIcon = ID
            'QTA
            ITMX.SubItems(5) = STRDBROWS(5, K)
            'PREZZO
            ITMX.SubItems(6) = Format$(STRDBROWS(6, K), "#,##0.00")
            'TOTALE
            ITMX.SubItems(7) = Format$(STRDBROWS(7, K), "#,##0.00")
            'DATA
            ITMX.SubItems(8) = STRDBROWS(8, K)
            'ORA
            ITMX.SubItems(9) = STRDBROWS(9, K)

            'DATA CANC
            If Not IsNull(STRDBROWS(10, K)) Then
                ITMX.SubItems(10) = STRDBROWS(10, K)
                ITMX.ListSubItems(10).ForeColor = vbRed
            End If

            'ORA CANC
            If Not IsNull(STRDBROWS(12, K)) Then
                ITMX.SubItems(11) = STRDBROWS(12, K)
                ITMX.ListSubItems(11).ForeColor = vbRed
            End If

            'IDNAME
            If Not IsNull(STRDBROWS(13, K)) Then
                ITMX.SubItems(12) = STRDBROWS(13, K)
            Else
                ITMX.SubItems(12) = ""
            End If

            ITMX.SubItems(13) = STRDBROWS(11, K)

            If Not IsNull(STRDBROWS(14, K)) Then
                ITMX.SubItems(14) = STRDBROWS(14, K)
            Else
                ITMX.SubItems(14) = ""
            End If

        Next K

        Set ITMX = Nothing

        Me.LNR.Caption = .ListItems.Count
        .Visible = True

        SendMessage .hwnd, WM_SETREDRAW, 1, ByVal 0

        Screen.MousePointer = vbDefault

        'LockWindowUpdate 0&

    End With

End Sub
 
 https://files.engineering.com/getfile.aspx?folder=0fc81b23-cd64-469f-921a-937710c87bdd&file=VID_20220414_192850.zip
How do you know your [tt]Sub APRI_LISTVIEW()[/tt] is running twice?
Where do you Call this Sub from?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
>why twice fresh?

NBot quite sure I understand the question. Is the Listview refreshing twice, but the routine is only being called once? Or is the routine being called twice (in which case we need to see more of your code)?

By the way, why do you insist on getting the recordset into an array, and then populating the listView from the array, when you can populate the LV directl;y from the recordset (we've kind of hinted about this in the past - you seem fixated on using arrays to move your data about, and it often seems the least efficient way)
 
>getting the recordset into an array
Maybe a personal preference. I had a co-worker who did the same, and then copied the array to another array, and then copied it yet again. Then changed some elements of some arrays. A nightmare to maintain.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
you saw the video attached?

sorry for fresh, is a refresh/repaint!

i call from an Image on click event whith:

Private Sub Image1_Click()

Screen.MousePointer = vbHourglass
MOD_COMANDA.Show (1)
Me.Text1.SetFocus

End Sub

Private Sub Form_Initialize()

Call STOP_MOVE(Me.Caption)

Call FILL_CTAVOLI
Call FILL_CGIORNO
Call FILL_COMANDA
Call APRI_IMAGE_COMBO

SQL = "SELECT * FROM COMANDA_TAVOLI"
Call APRI_LISTVIEW '<<<<

End Sub

note:
i store the recordset in Array to speed up the filling of Listview.
 
Ok, my first advice would be to either try removing the paired .Visible statements, or the paired SendMessage (although I don't think that is the issue - but you don't need both of them in any case).

Personally, I think you are somehow managing to run the same code as in the initialize event more than once. Just cannot see how from the code you have shown us so far.
 
You could place a break point in the [tt]Private Sub Form_Initialize()[/tt] and if your [tt]APRI_LISTVIEW()[/tt] is really called only from there, you should be able to trace why the [tt]Form_Initialize()[/tt] is called twice.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
>Form_Initialize() is called twice

It is really difficult to achieve that in a running VB program - unless you call the Initialize event directly yourself (once a VB form has been initialised it tends to hang around, even if you Unload it). So yes, it'll be interesting to see what debugging reveals (which, let's be honest, should have been attempted already ...)
 
Are you using the Form's name when referring to it from inside the form. That could kick off initialize I think.
 
Nope. Firstly initialize is only ever called once during a form's lifetime form (unless it is completely terminated, which it takes from very explicit code to achieve that I don't expect sal21 to have implemented.) The effect you refer to - self-instancing - will not kick off another initialize event if the form has not already been terminated, particularly if triggered from within the form itself (since clearly for that to occur the form already exists)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top