Save/Export Listbox Content to a file !?
-
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.
-
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.
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[^]
-
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.
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[^]
-
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[^]
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