Results 1 to 2 of 2

Thread: Add strings to a stringcollection or list

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2021
    Posts
    6

    Question Add strings to a stringcollection or list

    how can I add strings to a stringcollection in the settings, or add items to a list(Of String/Object) and how do you add it the items back in the stringcollection or (Of String/Object) to a Listbox.

    Example:
    Code:
    StringCollection.Add(String)
    I'm basically trying to store items into a listbox and I run a certain function, it will add the items to a Listbox.

    Code:
    StringCollection.AddRange(ListBox)
    Last edited by dday9; May 14th, 2021 at 09:59 AM. Reason: Added Code Tags

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,762

    Re: Add strings to a stringcollection or list

    When your form loads, get the items using:
    Code:
    Dim values = If(My.Settings.MySettingName?.Count > 0, My.Settings.MySettingName, New Specialized.StringCollection())
    MyListBox.Items.AddRange(values.Cast(Of String).ToArray())
    Then when you want to add a value to to the collection, use:
    Code:
    Dim value = InputBox("New Value: ")
    If (My.Settings.MySettingName Is Nothing) Then
        My.Settings.MySettingName = New Specialized.StringCollection() From { value }
    Else
        My.Settings.MySettingName.Add(value)
    End If
    My.Settings.Save()
    MyListBox.Items.Add(value)
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

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