Results 1 to 12 of 12

Thread: Populating listview

  1. #1

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Populating listview

    I guess this will be fairly tricky(maybe not) so i'm hoping somebody knows of a tutorial or pre-made code for populating a listview from a text list.

    My text list data has 2 delimiters "|" and "," and is of the form

    path filename|filesize,path filename|filesize etc

    example being c:\file1.exe|34502,c:\file2.exe|31233..etc.

    Well my task is to read any length of list, as in the example, and display in a suitable way.

  2. #2

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    I sorted most of this out apart from one thing, how to you extract part of a string that lies inbetween 2 different delimiters?

    like ,file1.exe|32123,file2.exe|432432,

    So i need the split to start at the "," and stop at the "|" so as to extract the file size .

    I need a kinda reverse Mid that allows characters delims.
    Last edited by Jmacp; Apr 11th, 2004 at 08:09 AM.

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Split first on "," you'll get an array from that, say arrFirst(). To assign the pair into separate columns in the listview, loop through arrFirst, split each line on "|" and assign the result to .Text = arrSecond(0) .SubItem(1) = arrSecond(1)

  4. #4

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    I keep on getting runtime error 9, out of subscript, i think whats happeneing is its running through the loop one more time than it should, hard to explain but i can't seem to fit a condition in to stop the loop at a certain length.

    Anybody know of any code that would fit this situation, it has to be able to parse a string with 2 delims and populate the listview with the filename in one columm and the respective filesize in the other.


    my string is in the form,

    VB Code:
    1. ....test.exe|6327,text2.exe|4776,test3.exe....and on|

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Do you have to put them in columns? Can you just put them as subitems of listview items and use HitTest to get their values?


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Use Replace first

    c:\file1.exe|34502,c:\file2.exe|31233..etc.

    Replace either the | with , or vice versa so the delimter is the same. Then Split it into an Array.

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Originally posted by BrianS
    Use Replace first

    c:\file1.exe|34502,c:\file2.exe|31233..etc.

    Replace either the | with , or vice versa so the delimter is the same. Then Split it into an Array.
    And step through the loop in 2s instead of the default 1

  8. #8

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    I got it, thanks.

    One more thing, the scrollbar doesn't appear in the listview when the list exceeds the height. I am using this(below), to auto resize the listview and treeview if that makes a difference,

    VB Code:
    1. Public Sub Form_Resize()
    2.  
    3.      lvFiles.Width = Me.Width
    4.     lvFiles.Height = Me.Height
    5.     TvTreeView.Height = Me.Height
    6.  
    7. End Sub

    In fact it doesnt appear even if i don't resize.

  9. #9

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    Anybody know how to get the vertical and idealy horizontal scrollbar to appear in my listview, it doesn't by default and there doesn't seem to be an option to add one in the properties ?


  10. #10
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    I am really curious...never seen the listview do this - is it possible for you to upload your project?
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  11. #11
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    If your Listview and Treeview controls are side by side on the Form, then the width of the Listview should take into account the width of the Treeview.

    I think the listview is extending off the form, the scrollbars are offscreen.

    This assumes the Treeview is on the left side and Listview is on the right.

    VB Code:
    1. Public Sub Form_Resize()
    2.     If WindowState <> vbMinimized then
    3.         If Me.ScaleWidth > tvTreeview.Width + 100 'otherwise an error if the form is resized smaller than the width of the treeview
    4.            lvFiles.Width = Me.ScaleWidth - tvTreeview.Width
    5.         End If
    6.         lvFiles.Height = Me.ScaleHeight
    7.        TvTreeView.Height = Me.ScaleHeight  
    8.     End If
    9. End Sub

    Use the ScaleWidth and ScaleHeight properties of the Form instead. They represent the client area of the form. I.E. they do not include the title bar , borders, menus etc..
    Last edited by brucevde; Apr 12th, 2004 at 11:33 AM.

  12. #12

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    Ok thanks thats what i thought might be happening but i've just taken the form resize out and still no scrollbar, shouldn't the scrollbar appear automatically ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width