locked
ListView Item column sum RRS feed

  • Question

  • I have a listView and i want the column sum in text box how can i do?

     

    Friday, August 13, 2010 10:43 AM

Answers

  • Maybe something like this:

    int iSum = 0;
    foreach (ListViewItem o in this.lstLinks.Items) {
    	iSum = iSum + Convert.ToInt16(o.SubItems(3).Text);
    }
    
    Here I assume the value field is in the third subitems.
    Best regards Arild Røksund, Norwegian developer (SQL & .net), Omega AS (please Vote as helpful if helpful)
    Friday, August 13, 2010 11:23 AM

All replies

  • Iterate through the items in the ListView and add them to a total - you probably need to convert them to a numeric such as int or double.

    If the column is not the first one you need to use the SubItem that corresponds to the column.


    Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.
    Friday, August 13, 2010 10:51 AM
  • Maybe something like this:

    int iSum = 0;
    foreach (ListViewItem o in this.lstLinks.Items) {
    	iSum = iSum + Convert.ToInt16(o.SubItems(3).Text);
    }
    
    Here I assume the value field is in the third subitems.
    Best regards Arild Røksund, Norwegian developer (SQL & .net), Omega AS (please Vote as helpful if helpful)
    Friday, August 13, 2010 11:23 AM