How do i sum the 2 columns per row using listView c#
How do i sum the 2 columns per row using listView c#
I'm using c# windows form. how do i sum the 2 Colums per row using listView? and divide it into 2? and the total will show in 3rd column?
this is my example code, my code sum all of the sub items and i cant view it on the 3rd column.
private void button1_Click_1(object sender, EventArgs e)
foreach (ListViewItem lstItem in listView1.Items)
gtotal = int.Parse(lstItem.SubItems[2].Text);
total += int.Parse(lstItem.SubItems[3].Text);
totals = int.Parse(lstItem.SubItems[4].Text);
I agree with @Plutonix. Is there a specific reason why you're using a
ListView
? A DataGridView
would be much easier to work with for your purpose.– Sach
Aug 28 at 17:24
ListView
DataGridView
1 Answer
1
private void button1_Click_1(object sender, EventArgs e)
foreach (ListViewItem lstItem in listView1.Items)
gtotal = int.Parse(lstItem.SubItems[2].Text); //Detail Column
total = int.Parse(lstItem.SubItems[3].Text); //Detail2 Column
lstItem.SubItems[4].Text = gtotal + total // Sum of 2 Column of details
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
FWIW, it is much easier to use a DataGridView for this because it is an actual grid control and can store numbers
– Disaffected 1070452
Aug 28 at 17:20