calculate sum of column total in LISTview in C#
while (rd.Read())
{
usersNB.Add(new userNB
{
//my sql
Vrijeme = rd.IsDBNull(rd.GetOrdinal("VRIJEME")) ? string.Empty : rd.GetString(rd.GetOrdinal("VRIJEME")),
Osoba = rd.GetString("OSOBA"),
Sati = rd.IsDBNull(rd.GetOrdinal("SATI")) ? string.Empty : rd.GetInt32(rd.GetOrdinal("SATI")).ToString()
}
Need to sum last column SATI
Naimish MakwanaPosted Jan 22, 2024, 8:57 AM
To calculate the sum of the column
SATIin aListView, you can iterate over the items in theListViewand add the values of theSATIcolumn. Here is an example of how you can do it:In this code,
listView1is the name of yourListView. This code assumes that theSATIcolumn values are integers. If they are not, you may need to adjust the parsing method accordingly. Please replacelistView1and"SATI"with your actualListViewname and column name.Please note that this is a simple example and error checking is not included. You might want to add error checking to ensure that the values in the
SATIcolumn can be parsed to integers. If theSATIcolumn might have null or empty values, you should check for these before trying to parse the values.Also, this code should be placed where it makes sense in your program, such as after you’ve finished adding items to the
ListView.Thanks