Connecting Tech Pros Worldwide Forums | Help | Site Map

How do I get control over the text of a listbox items in VB.Net

Newbie
 
Join Date: Sep 2008
Posts: 3
#1: Sep 30 '08
I was trying to sum up all the items of a listbox in Visual Studio 2005. I tried to loop (from 0 to ListBox.Items.Count - 1) as follows


For j as Integer = 0 to ListBox.Items.Count - 1
sum = sum + val(ListBox.Items.Item(j))
Next

My problem is: the sum variable keeps returning 0, and the
ListBox.Items.Item(j) does not have a text property or value property. So, please how do I get hold on the text of an item of a listBox in VB.Net?
My OS is Vista Home Premium

shweta123's Avatar
Expert
 
Join Date: Nov 2006
Location: India,Pune
Posts: 686
#2: Sep 30 '08

re: How do I get control over the text of a listbox items in VB.Net


Hi,

Please check the no of items in the listbox.It is possible that the no of items in the listbox are zero because of it, the code written for doing sum in the For Loop is not executed.


Quote:

Originally Posted by PaulBrains

I was trying to sum up all the items of a listbox in Visual Studio 2005. I tried to loop (from 0 to ListBox.Items.Count - 1) as follows


For j as Integer = 0 to ListBox.Items.Count - 1
sum = sum + val(ListBox.Items.Item(j))
Next

My problem is: the sum variable keeps returning 0, and the
ListBox.Items.Item(j) does not have a text property or value property. So, please how do I get hold on the text of an item of a listBox in VB.Net?
My OS is Vista Home Premium

Reply