Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net Save new ListBox items so that they are loaded back in next time the form is open

Posted on 2012-04-09
2
Medium Priority
?
1,402 Views
Last Modified: 2012-04-09
Hi


In VB.net 2010 I have a ListBox that the user adds to or deletes items from. I want to be able to save what is in the ListBox, which may contain up to 100 entries. What is the best way to do this? Should I perhaps make one long string out of it and save this as a Setting, or should I write this to a text file. I am always weary of the latter because some of the issue of not being able to write to certain drives and as far as the former goes, I'm not sure how long a string one can save in a single setting.

Any suggestions would be very helpful.

Thanks
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 37823602
Saving as one long string in Settings would work just fine.  You'd need to pick your delimiter carefully though.  Will the comma "," or pipe "|" ever appear in the entries of the ListBox?

Here's a simple example using the pipe:
Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim values As String = My.Settings.ListBoxValues
        If values <> "" Then
            ListBox1.Items.Clear()
            ListBox1.Items.AddRange(values.Split("|"))
        End If
    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim values As New List(Of String)
        For Each item As String In ListBox1.Items
            values.Add(item)
        Next
        My.Settings.ListBoxValues = String.Join("|", values.ToArray)
        My.Settings.Save()
    End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:Murray Brown
ID: 37823665
Great answer! Thanks very much
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

671 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