Answered by:
How to retrieve all the rows from ListView and store it in a string array or ArrayList c#?

Question
-
Hi All !!
I have a listview which displays patient information like Name, Age, Sex, DOB. Now i need to display all the rows of the listview using a string array or ArrayList. Please help me to finish it.
Thanks in Advance !!
:> Known is a Drop, UnKnown is an Ocean <:Friday, June 3, 2011 5:03 AM
Answers
-
Hi,
you an retreive all rows (with columns) on many ways. Its true that getting items out of listView into string array or ArrayList isnt the best solution, but if you insist I can show you one of the ways. One row from listView will be stored into one index of array into array list:
//method to retreive items 8and subitems) from listView: ArrayList aList = new ArrayList(); string delimiter = ";"; for(int i = 0; i< listView.Items.Count; i++) { string columns = String.Empty; columns += listView1.Items[i].Text + delimiter; columns += listView1.Items[i].Subitems[1].Text + delimiter; columns += listView1.Items[i].Subitems[2].Text + delimiter; columns += listView1.Items[i].Subitems[3].Text; aList.Add(columns); } //to show results: StringBuilder sb = new StringBuilder(); foreach(string line in aList) sb.AppendLine(line); MessageBox.Show(sb.Tostring());
Mitja- Proposed as answer by Vishvvas Monday, June 6, 2011 6:49 AM
- Marked as answer by Mike Dos Zhang Thursday, June 9, 2011 2:51 PM
Friday, June 3, 2011 7:52 AM
All replies
-
What is bound to Listview when it is displaying the patient infromation or this is what you want to achive? Please refer following articles which can help to achieve data binding
http://www.codeproject.com/KB/list/ListView_DataBinding.aspx
http://msdn.microsoft.com/en-us/magazine/cc301575.aspx
Hope this helps.
ThanksFriday, June 3, 2011 5:22 AM -
Hi Vishwas !!
Thanks a lot for ur response , Actually getting the values to the ListView from Database. Now the listview has some rows with Name, Age, Sex Colums, My doubt is very simple, What i want is , just want to get the rows from the ListView , need to store it in a String array. That's it.
:> Known is a Drop, UnKnown is an Ocean <:Friday, June 3, 2011 6:20 AM -
Hi,
you an retreive all rows (with columns) on many ways. Its true that getting items out of listView into string array or ArrayList isnt the best solution, but if you insist I can show you one of the ways. One row from listView will be stored into one index of array into array list:
//method to retreive items 8and subitems) from listView: ArrayList aList = new ArrayList(); string delimiter = ";"; for(int i = 0; i< listView.Items.Count; i++) { string columns = String.Empty; columns += listView1.Items[i].Text + delimiter; columns += listView1.Items[i].Subitems[1].Text + delimiter; columns += listView1.Items[i].Subitems[2].Text + delimiter; columns += listView1.Items[i].Subitems[3].Text; aList.Add(columns); } //to show results: StringBuilder sb = new StringBuilder(); foreach(string line in aList) sb.AppendLine(line); MessageBox.Show(sb.Tostring());
Mitja- Proposed as answer by Vishvvas Monday, June 6, 2011 6:49 AM
- Marked as answer by Mike Dos Zhang Thursday, June 9, 2011 2:51 PM
Friday, June 3, 2011 7:52 AM -
Hi tamilan2233,I am writing to check the status of the issue on your side.What about this problem now?Would you mind letting us know the result of the suggestions?Best wishes,
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, June 6, 2011 10:21 AM -
ArrayList lviArrayList = new ArrayList(listView1.Items);
Monday, June 6, 2011 1:40 PM