Need help with contact list

fantity

Active member
Joined
Mar 10, 2012
Messages
27
Programming Experience
Beginner
I am wanting to add a contact list to my program. I have a setting set called "contacts". I want the user to be able to type the person's name and email address. I have tried a code already but it won't work.

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Settings.Contacts.Add(TextBox1.Text & TextBox2.Text)
        TextBox1.Text = ""
        TextBox2.Text = ""
        Form3.ListBox1.Items.Clear()
        My.Settings.Save()
        Me.Close()
    End Sub

Please help me
 
I am wanting to add a contact list to my program. I have a setting set called "contacts". I want the user to be able to type the person's name and email address. I have tried a code already but it won't work.

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Settings.Contacts.Add(TextBox1.Text & TextBox2.Text)
        TextBox1.Text = ""
        TextBox2.Text = ""
        Form3.ListBox1.Items.Clear()
        My.Settings.Save()
        Me.Close()
    End Sub

Please help me

Have you tried debugging the code to see what is happening?
What type is Contacts? and what scope is the variable in the Settings, Application or User?
 
Have you tried debugging the code to see what is happening?
What type is Contacts? and what scope is the variable in the Settings, Application or User?

Yes I have debugged it and It will only add one word of text and won't save after close. It is a string setting with user.
 
You're using a string to store a collection. Try setting the type to System.Collections.Specialized.StringCollection.
 
You're using a string to store a collection. Try setting the type to System.Collections.Specialized.StringCollection.

I changed it and the settings save now. but I can't delete them. This is my delete button code:

VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            ListBox1.Items.Remove(ListBox1.SelectedItem)
            My.Settings.Contacts.Remove(ListBox1.SelectedItem)
            My.Settings.Save()


        Catch ex As Exception


        End Try
    End Sub
 
Back
Top