Results 1 to 10 of 10

Thread: Wanting to (save) items to colection in a listbox programatically

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    82

    Wanting to (save) items to colection in a listbox programatically

    Hi everyone, What I want to do is save items (using drag and drop) that have been added from (listbox1) to (listbox2), so that when I restart the application again they will still be there (persistence). I should add that I might not want all items in listbox1, just the one's that I select.

    here is my code to date"

    HTML Code:
     Private Sub listbox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
    
            ListBox1.DoDragDrop(ListBox1, DragDropEffects.Copy)
        End Sub
    
        Private Sub ListBox2_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragEnter
            ListBox2.Items.Add(ListBox1.SelectedItem)
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            ListBox2.Items.Add(ListBox2.Text)
        End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Wanting to (save) items to colection in a listbox programatically

    This really has nothing to do with drag-n-drop. How the items get into the ListBox is irrelevant. If you want to do something with the items in a ListBox then you use its Items collection to access them. If you want to do something with the selected items in a ListBox then you use its SelectedItems collection to access them. If you want to persist a list of items between application sessions then you add a StringCollection on the Settings page of the project properties and then retrieve your items from it at startup and populate it with your items at shutdown. Put those pieces together and you have your solution.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    82

    Re: Wanting to (save) items to colection in a listbox programatically

    Quote Originally Posted by jmcilhinney View Post
    This really has nothing to do with drag-n-drop. How the items get into the ListBox is irrelevant. If you want to do something with the items in a ListBox then you use its Items collection to access them. If you want to do something with the selected items in a ListBox then you use its SelectedItems collection to access them. If you want to persist a list of items between application sessions then you add a StringCollection on the Settings page of the project properties and then retrieve your items from it at startup and populate it with your items at shutdown. Put those pieces together and you have your solution.
    Thank you, I am aware that drag and drop has nothing to do with the saving of the items, it's the saving of the (Items) that I wanted to know. The other information was to make my intentions more clearer.

    So do I understand you correctly, that I will need to, on the settings heading, add (system.Collections.Specialized.String.collection)
    and save the added items to this?

    Can you recommend and examples of this?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Wanting to (save) items to colection in a listbox programatically

    Quote Originally Posted by Minch View Post
    So do I understand you correctly, that I will need to, on the settings heading, add (system.Collections.Specialized.String.collection)
    and save the added items to this?
    Yes.
    Quote Originally Posted by Minch View Post
    Can you recommend and examples of this?
    I could, but I'd have to search for it on the web, which you can do as well as I.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    82

    Re: Wanting to (save) items to colection in a listbox programatically

    Why bother even answering my post.
    I think you need to ask yourself, am I helping people or am I here just for my ego.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Wanting to (save) items to colection in a listbox programatically

    So, are you saying that you already knew that you should use a StringCollection added to the applications settings to do this? If not then I HAVE helped you, so what exactly are you complaining about? I don't have any links to examples of doing this lying around. Are you implying that I have some responsibility to go and find some for you rather than your having to search for yourself? I think you need to ask yourself, do I want to learn to do for myself or am I just here for a handout.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    82

    Re: Wanting to (save) items to colection in a listbox programatically

    Quote Originally Posted by jmcilhinney View Post
    So, are you saying that you already knew that you should use a StringCollection added to the applications settings to do this? If not then I HAVE helped you, so what exactly are you complaining about? I don't have any links to examples of doing this lying around. Are you implying that I have some responsibility to go and find some for you rather than your having to search for yourself? I think you need to ask yourself, do I want to learn to do for myself or am I just here for a handout.
    No I did not know you idiot, that's why I asked the forum. I was NOT looking for a handout just some basic information, you are, unhelpful and sarcastic. If you don't want to help people just don't reply. That would do us all a favour. Go back to your little fantasy world and tell yourself how good you are.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Wanting to (save) items to colection in a listbox programatically

    Quote Originally Posted by Minch View Post
    No I did not know you idiot, that's why I asked the forum.
    And I told you, so I helped you. I guess I can answer "yes" when I ask myself whether I am helping people.
    Quote Originally Posted by Minch View Post
    I was NOT looking for a handout just some basic information
    And I gave you some basic information, so I'm still not seeing what the actual problem is.
    Quote Originally Posted by Minch View Post
    you are, unhelpful and sarcastic.
    You said yourself that I provided information of which you weren't aware so you're obviously lying when you say that I'm unhelpful. Why would you do that? Perhaps I didn't provide as much help as you felt you were entitled to, but that doesn't actually mean that you were entitled to it. I've been known to bring out the sarcasm on occasions but there actually was none at all in post #4. It was simply a statement of fact. If I had to guess, I'd suggest that a guilty conscience could be to blame for that mistake. It's not unusual for people to go on the offensive in order to distract everyone, themselves included, from what they think they've done wrong.
    Quote Originally Posted by Minch View Post
    If you don't want to help people just don't reply.
    I do want to help, which is why I replied, and I did help. You just expected more help than I had to provide. What did I do that was so bad? I told you that I would have to search the web in order to provide examples but, as you are just as capable of doing that as I am, I was leaving it to you. What exactly is wrong with that? Do you think that I should have searched the web so that you didn't have to? Do you think that I should have simply ignored your question? What would you have done in that situation?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    82

    Re: Wanting to (save) items to colection in a listbox programatically

    Quote Originally Posted by jmcilhinney View Post
    And I told you, so I helped you. I guess I can answer "yes" when I ask myself whether I am helping people.

    And I gave you some basic information, so I'm still not seeing what the actual problem is.

    You said yourself that I provided information of which you weren't aware so you're obviously lying when you say that I'm unhelpful. Why would you do that? Perhaps I didn't provide as much help as you felt you were entitled to, but that doesn't actually mean that you were entitled to it. I've been known to bring out the sarcasm on occasions but there actually was none at all in post #4. It was simply a statement of fact. If I had to guess, I'd suggest that a guilty conscience could be to blame for that mistake. It's not unusual for people to go on the offensive in order to distract everyone, themselves included, from what they think they've done wrong.

    I do want to help, which is why I replied, and I did help. You just expected more help than I had to provide. What did I do that was so bad? I told you that I would have to search the web in order to provide examples but, as you are just as capable of doing that as I am, I was leaving it to you. What exactly is wrong with that? Do you think that I should have searched the web so that you didn't have to? Do you think that I should have simply ignored your question? What would you have done in that situation?
    I think your real name is DONALD TRUMP. or someone who thinks like him. Big ego, full of BS and lives in his own world. Don't reply to any of my posts in future!!

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Wanting to (save) items to colection in a listbox programatically

    I see. No actual explanation of what I did wrong and what you would have done better. It's very clear what's going on here. I won't reply further to this thread but I'll reply to whatever threads I see fit in future. If I'm not helpful, or even if I am, you're free to ignore my posts. I guess you won't be using a StringCollection in the application settings here either, given that that bit of advice was so unhelpful.

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