Results 1 to 3 of 3

Thread: [RESOLVED] Populate Listview with files in my.resources

  1. #1

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Resolved [RESOLVED] Populate Listview with files in my.resources

    Hello, I wonder if you can help me please.

    I have a very simple program which simply populates a listbox with a list of files stored in a directory.
    Code:
            Try
                lvScripts.View = View.Details
                lvScripts.Items.Clear()
                lvScripts.Columns.Clear()
    
                lvScripts.Columns.Add("Filename", 250, HorizontalAlignment.Left)
    
                Dim dFolder As DirectoryInfo = New DirectoryInfo(ScriptDirectory)
                Dim fFileArray() As FileInfo = dFolder.GetFiles
                Dim fFile As FileInfo
                Dim lCurrent As ListViewItem
    
                For Each fFile In fFileArray
                    lCurrent = lvScripts.Items.Add(fFile.Name)
                Next
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    However, I'd like to embed these files into the application itself and open them from there rather than from looking at the directory.

    To this end I've added each of the files as a resource but I don't know how to populate the list view with a list of the text files in the my.resources rather than a list of the text files in the directory.

  2. #2
    Member
    Join Date
    May 2011
    Posts
    38

    Re: Populate Listview with files in my.resources

    You can try calling ResourceManager.GetResourceSet() and iterating through the ResourceSet it returns.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Populate Listview with files in my.resources

    mf12's idea was correct. here's how:

    vb Code:
    1. Dim ResourceSet As Resources.ResourceSet = My.Resources.ResourceManager.GetResourceSet(Globalization.CultureInfo.CurrentCulture, True, True)
    2.         ListView1.Items.AddRange(ResourceSet.Cast(Of DictionaryEntry) _
    3.                                                   .Select(Function(d) New ListViewItem(d.Key.ToString)).ToArray)
    Last edited by .paul.; Sep 21st, 2011 at 11:37 AM. Reason: improvement

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