Results 1 to 6 of 6

Thread: listbox Help

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Question listbox Help

    is there a way to retrieve text value from a listbox based on index ?

    like if i enter index 0 and want to retrieve it's text value from the listbox

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: listbox Help

    Access the Items collection, i.e:

    vb.net Code:
    1. Dim value As String = Me.ListBox1.Items(0).ToString()

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: listbox Help

    thanks alot
    one more question if you please
    if i have many items in my listbox and in some of them ther's symbol (%u) and i want to replase it with certain text but the items index could change any time
    how to do this?

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: listbox Help

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    4.         MyBase.OnLoad(e)
    5.  
    6.         Me.ReplaceListBoxText(Me.ListBox1, "u%", String.Empty)
    7.  
    8.     End Sub
    9.  
    10.     Public Sub ReplaceListBoxText(ByVal lb As ListBox, _
    11.                                   ByVal find As String, _
    12.                                   ByVal replacement As String)
    13.  
    14.         '//loops all items
    15.         For index = 0 To lb.Items.Count - 1
    16.             lb.Items(index) = lb.Items(index).ToString() _
    17.                                              .Replace(find, replacement)
    18.         Next
    19.  
    20.     End Sub
    21.  
    22. End Class

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: listbox Help

    i make it that way
    vb Code:
    1. dim i as integer = answer.indexof("any word")
    2.                         Dim sshort As String = answer.Items(i).ToString
    3.                         Dim suser As String = Replace(sshort, "%u", sNic)

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: listbox Help

    i want to add to my listbox long string and i get this error

    the field is too small to accept the amount of data you attempted to add. try to inserting or pasting less data

    how can i make my list box accept long string item

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width