6 Replies - 262 Views - Last Post: 08 May 2013 - 04:55 PM Rate Topic: -----

#1 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 143
  • Joined: 07-October 12

Removing a Value from Specialized String

Posted 08 May 2013 - 04:06 PM

I'm trying to make a string collection modifiable and as of right now I have.
  
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ListBox1.Items.Add(TextBox1.Text)
        My.Settings.Bookmarks.Add(TextBox1.Text)
        My.Settings.Save()
    End Sub



That's what I'm using to add Bookmarks, but I'm having issues removing.
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Remove(ListBox1.SelectedItem)
        My.Settings.Bookmarks.Remove(ListBox1.SelectedItem)
        My.Settings.Save()
    End Sub



Does anyone have any idea why it's not working?

Is This A Good Question/Topic? 0
  • +

Replies To: Removing a Value from Specialized String

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,913
  • Joined: 25-September 09

Re: Removing a Value from Specialized String

Posted 08 May 2013 - 04:14 PM

Since SelectedItem is of Type Object and bookmarks is a specialized string collection. I would try adding .ToString to the selecteditem.

At the top of your code, Set Option Strict On before trying my suggestion. I would think that it would flag the remove line with an error to do with passing an object where a string is expected in the remove method.
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,913
  • Joined: 25-September 09

Re: Removing a Value from Specialized String

Posted 08 May 2013 - 04:37 PM

OK, I just played with this and I think the issue is, you're removing the selecteditem from the listbox before removing it from the settings. Which means that there either is no item selected at the time of removal from the settings or it's removing the wrong item. (The latter would depend on if focus switches when you remove the first item)

This post has been edited by CharlieMay: 08 May 2013 - 04:39 PM

Was This Post Helpful? 1
  • +
  • -

#4 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 143
  • Joined: 07-October 12

Re: Removing a Value from Specialized String

Posted 08 May 2013 - 04:37 PM

Object reference not set to an instance of an object.

Just kinda teaching myself right now, so I'll try to figure out how to fix that.
Was This Post Helpful? 1
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,913
  • Joined: 25-September 09

Re: Removing a Value from Specialized String

Posted 08 May 2013 - 04:46 PM

in case you missed it, make sure you read my post #3 because adding .ToString would cause that error in that situation.
Was This Post Helpful? 0
  • +
  • -

#6 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 143
  • Joined: 07-October 12

Re: Removing a Value from Specialized String

Posted 08 May 2013 - 04:50 PM

You're correct. Something so simple yet seemed so complicated. Sorry; I missed the post #3. Appreciate the help and time.
Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,913
  • Joined: 25-September 09

Re: Removing a Value from Specialized String

Posted 08 May 2013 - 04:55 PM

LOL, yea, that's usually the ones that get ya!

Keep testing yourself. It's refreshing when we see someone doing things to better themselves.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1