|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++)
Hope this will help someone else. (of course you can personalize it like adding savefiledialog...)