×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

as if loading the listview twice

as if loading the listview twice

as if loading the listview twice

(OP)
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 

RE: as if loading the listview twice

How do you know your Sub APRI_LISTVIEW() is running twice?
Where do you Call this Sub from?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: as if loading the listview twice

>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)

RE: as if loading the listview twice

>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

RE: as if loading the listview twice

(OP)
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.

RE: as if loading the listview twice

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.

RE: as if loading the listview twice

You could place a break point in the Private Sub Form_Initialize() and if your APRI_LISTVIEW() is really called only from there, you should be able to trace why the Form_Initialize() is called twice.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: as if loading the listview twice

>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 ...)

RE: as if loading the listview twice

Are you using the Form's name when referring to it from inside the form. That could kick off initialize I think.

RE: as if loading the listview twice

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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close