listview data not in view

Posted on 2007-10-11
Last Modified: 2013-12-26
Hi Experts,

I am using the code below to load a listview on a form with records held in a memo field these records are kept as cvs records each record also being seperated by a comma each record has eight values the code strips out the last two fields in the array and builds the listview with the data(szGoodsDesc fields =
"998899, Battery Acid 5000 Ltr, 5, Euro Pallets         Stackable, 1200, 600, 1000, 5000,
888997766, Car Widget No5 10000, 10, Standard Pallets  Stackable, 1200, 1200, 1000, 1000,
" )
                Dim cntr As Integer = 0
                Dim LoadArray(0, 8) As String
                sSeltxt = rst.Fields("szGoodsDesc").Value
                aryInputs = Split(sSeltxt & ",", ",") 'breaks it up by commas.
                Dim xx As Integer, X As Integer
                i = 0
                X = UBound(aryInputs)
                X = X / 8
                Dim y As Integer = 1
                Do While y < X
                    For i = LBound(aryInputs) To X * 8 removes extra fields from the array
                        xx = i
                        If (xx) > 7 And cntr = 1 Then xx = xx - 8
                        If (xx) > 7 And cntr = 2 Then xx = xx - 16
                        aryBits = Split(aryInputs(i), ",") 'Splits the item at the = character
                        sSeltxt = aryBits(0) 'Gets current csv and assigns to appropriate textbox
                        LoadArray(0, xx) = sSeltxt
                        If xx = 7 Then  code to make headers
                            ListViewMakeColumnHeaders(Me.Loadlist, _
                        "Part Number", HorizontalAlignment.Left, _
                        "Description", HorizontalAlignment.Left, _
                        "Num Pallets", HorizontalAlignment.Left, _
                        "Packaged", HorizontalAlignment.Left, _
                        "L", HorizontalAlignment.Center, _
                        "W", HorizontalAlignment.Center, _
                        "H", HorizontalAlignment.Center, _
                        "KG", HorizontalAlignment.Center)
 code to make listview records
                            ListViewMakeRow(Me.Loadlist, _
                                                                                                   LoadArray(0, 0), _
                                                                                                   LoadArray(0, 1), _
                                                                                                   LoadArray(0, 2), _
                                                                                                   LoadArray(0, 3), _
                                                                                                   LoadArray(0, 4), _
                                                                                                   LoadArray(0, 5), _
                                                                                                   LoadArray(0, 6), _
                                                                                                   LoadArray(0, 7) _
                            cntr = cntr + 1
                        End If
                    y = y + 1
            End With

            Me.Loadlist.Columns(0).Width = 80
            Me.Loadlist.Columns(1).Width = 180
            Me.Loadlist.Columns(2).Width = 80
            Me.Loadlist.Columns(3).Width = 50
            Me.Loadlist.Columns(4).Width = 50
            Me.Loadlist.Columns(5).Width = 50
            Me.Loadlist.Columns(6).Width = 50
            Me.Loadlist.Height = 65
            Me.ToTweight.Top = Me.Loadlist.Bottom

            If Me.Loadlist.Items.Count <= 5 Then
                Me.Loadlist.Height = (Me.Loadlist.Items.Count * 17) + 40
                Me.Height = Me.Height + 18
End if

When the code is ran the everthing appears ok but the listview appears empty, if I close the form and re-run hey presto the records are exactly as they should be. Why does the listview records not appear when the form is first populated nothing changes either in code or in the record betweeen the two instances?

Question by:JoeBo747
    LVL 10

    Expert Comment

    Try debugging using breakpoint to see in what sequence is it initally not displaying the records when the form is first run.
    LVL 1

    Author Comment

    Hi digitalZo,

    I've debugged the procedure followed through the code and on both the first load and second load the code appears to load in exactly the same way. The only difference being that on the first load after the project is launched  the list doe's not appear populated (although if i do "msgbox(.recorcount)" i get a positive return) and on all other calls the listview shows records. Strange eh?

    LVL 26

    Expert Comment

    without seeing your full code, it is hard to say

    1. Loadlist.Clear()
    doesn't look like listview to me, if listview it should be Loadlist.Listitems.Clear

    2. aryInputs = Split(sSeltxt & ",", ",") 'breaks it up by commas.
    don't understand why to put extra , before split the string

    3. do you have on error resume next?
    comment it out
    LVL 1

    Author Comment


    Thanks for your response,  in answer to your points raised:

    1.      loadlist.clear() I have changed to loadlist.items.clear() . This is to clear the list between load events. ( loadlist is on form2 and is loaded when an item is selected on form1 and a button clicked)
    2.      I tried using vbcrlf after each 8 fields when the memo field is populated with the csv file. This resulted in the first field in record two being concatenated with the last field in record1, the extra , is dealt with by the code.
    3.      I have no resume next present in the code.

    The rest of the code loads data into other controls on the form from the same recorset that populates loadlist.

    LVL 26

    Accepted Solution

    >>loadlist.clear() I have changed to loadlist.items.clear() . This is to clear the list between load events. ( loadlist is on form2 and is loaded when an item is selected on form1 and a button clicked)

    if it is on the form2, you should do something like

    load form2
    ' propulate the listview

    LVL 1

    Author Comment


    Thanks for your help,  I have populated the listview from form1 and then opened the form, all is well thankyou!


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now