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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PaulBrains
    New Member
    • Sep 2008
    • 3

    #1

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

    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.C ount - 1) as follows


    For j as Integer = 0 to ListBox.Items.C ount - 1
    sum = sum + val(ListBox.Ite ms.Item(j))
    Next

    My problem is: the sum variable keeps returning 0, and the
    ListBox.Items.I tem(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
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    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.


    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.C ount - 1) as follows


    For j as Integer = 0 to ListBox.Items.C ount - 1
    sum = sum + val(ListBox.Ite ms.Item(j))
    Next

    My problem is: the sum variable keeps returning 0, and the
    ListBox.Items.I tem(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

    Comment

    Working...