Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am making app in WPF C# which connects with SQL Server. There is a listview in my app and i want to save each row in listview to database. My Listview consist of 4+ Column. So tell me the best way to save all rows in database at once. Usually i want this to happen on onclick event.

I tried this method:

C#
for (int i = 0; i < listview.Items.Count; i++)
{
String abc = listview.Items[i].Subitem[i].Text;
//other varables
}


But not working. I tried it with Listviewitem and with for and foreach loop. But underlined red color mean error is coming when i type .Text or Subitem or item[i]. Kindly tell the solution.
Posted
Updated 26-Nov-14 1:36am

 
Share this answer
 
v3
Comments
Burhan Ahmed 26-Nov-14 7:29am    
i type this listView1.Items[i].SubItems[3].Text and error will appear why
Burhan Ahmed 26-Nov-14 7:37am    
can u explain it more
Burhan Ahmed 26-Nov-14 7:40am    
it gives error that object does not contain defination for Text. It means Text property does not exist
Another way..
C#
foreach (ListViewItem item in listView1.Items)
{
   String abc = Convert.ToString(item.SubItems[1].Text);
//etc etc
 }
 
Share this answer
 
v2
Comments
Burhan Ahmed 26-Nov-14 8:24am    
http://www.codeproject.com/Questions/846829/How-to-get-values-from-Class

This is link where i added my xaml + cs code. Now tell me how i get item values and SubItems[1].Text is giving error
Burhan Ahmed 26-Nov-14 8:29am    
SubItems works in WinForms not in WPF
I think you are manually typed this line.

String abc = listview.Items[i].Subitem[i].Text;

The line should be,

String abc = listview.Items[i].SubItems[i].Text;


SubItems and not Subitem
 
Share this answer
 
Comments
Burhan Ahmed 26-Nov-14 10:15am    
read my comments above, subitem can used in winforms not wpf

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900