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);




This is my listView Table





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





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế