473,236 Members | 1,749 Online

# sum

How to make a Sum of listBox items?

Hrcko
Jan 2 '06 #1
4 3079
"Hrvoje Voda" <hr*********@luatech.com> a écrit dans le message de news:
dp**********@ss405.t-com.hr...

| How to make a Sum of listBox items?

Assuming all the items in the listbox are string representations of integers
:

{
int total = 0;

foreach (object o in listbox1.Items)
{
total += (int) Convert.ChangeType(o, typeof(int));
}
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 2 '06 #2
Or just simply:

int count = listbox.Items.Count;

Cheers
Simon.

"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:dp**********@ss405.t-com.hr...
How to make a Sum of listBox items?

Hrcko

Jan 2 '06 #3
"Simon Hart" <srhartone@[no spam]yahoo.com> a écrit dans le message de news:
uE****************@TK2MSFTNGP12.phx.gbl...
| Or just simply:
|
| int count = listbox.Items.Count;

Huh ? The term Sum means the total of all the values, not the Count.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 2 '06 #4
"Joanna Carter [TeamB]" <jo****@not.for.spam> wrote in message
news:eK****************@TK2MSFTNGP15.phx.gbl...
"Simon Hart" <srhartone@[no spam]yahoo.com> a écrit dans le message de
news:
uE****************@TK2MSFTNGP12.phx.gbl...
| Or just simply:
|
| int count = listbox.Items.Count;

Huh ? The term Sum means the total of all the values, not the Count.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Well it depends on context

If I asked for the sum total of items in the list I'd probably be after the
count. but if I asked for the sum of the items I'd probablt be asking got
the the sum across each item in teh list.

The problme is that on an English newsgroup in a heavily non-English
speaking world then both interpretations are valid and the OP needs to
provide more context.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Jan 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.