Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Save/Export Listbox Content to a file !?

Save/Export Listbox Content to a file !?

Scheduled Pinned Locked Moved C#
csharpdatabasequestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vantoora
    wrote on last edited by
    #1

    Hi Folks, I made one prog with C# to list some query in a listbox control, and I want it to be saved to a file like *.txt or *.csv or ... anyway I just want to save my listbox content but I don't know how if someone can give me some tips. thanks in advance for all and have a nice day.

    T 2 Replies Last reply
    0
    • V vantoora

      Hi Folks, I made one prog with C# to list some query in a listbox control, and I want it to be saved to a file like *.txt or *.csv or ... anyway I just want to save my listbox content but I don't know how if someone can give me some tips. thanks in advance for all and have a nice day.

      T Offline
      T Offline
      tech603
      wrote on last edited by
      #2

      I found that this tutorial had helped me when i had the very same question :). http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx[^] Matthew Vass QA Anylist mvass@hostmysite.com http://www.hostmysite.com?utm_source=bb[^]

      V 1 Reply Last reply
      0
      • V vantoora

        Hi Folks, I made one prog with C# to list some query in a listbox control, and I want it to be saved to a file like *.txt or *.csv or ... anyway I just want to save my listbox content but I don't know how if someone can give me some tips. thanks in advance for all and have a nice day.

        T Offline
        T Offline
        tech603
        wrote on last edited by
        #3

        I found that this tutorial helped me when i had the very same question http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx[^] Matthew Vass QA Analyst mvass@hostmysite.com http://www.hostmysite.com?utm_source=bb[^]

        1 Reply Last reply
        0
        • T tech603

          I found that this tutorial had helped me when i had the very same question :). http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx[^] Matthew Vass QA Anylist mvass@hostmysite.com http://www.hostmysite.com?utm_source=bb[^]

          V Offline
          V Offline
          vantoora
          wrote on last edited by
          #4

          Thanks for your reply but it does not what I expect to have. Maybe my question is not quiet clear so I'll explain first what I want to have. So I have one listbox that I populate with a result of a calculation. Let's say the listbox contains 100 items. What I need is to save those list items into a file (maybe I want them later even if I already closed the program for another process). What you showed me is just the way how to write into a file but not how to retrieve all value of the list and save them into a file. This is what I want. But, fortunately, I know now how to save the listbox contents : 1. I count the number of items : listbox1.Items.Count; 2. recursively set each Items selected : listbox1.SetSelected(i, true); and StreamWriter each selected Items directly. for example : int number = listbox1.Items.Count; StreamWriter sw = new StreamWriter(@"C:\list.csv"); for (int i = 0; i < number; i++) { listbox1.SetSelected(i, true); sw.WriteLine(listbox1.SelectedItems[i].ToString()); } sw.Close(); Hope this will help someone else. (of course you can personalize it like adding savefiledialog...) Cheers, :-D

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups