Results 1 to 9 of 9

Thread: Newbie question

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    55

    Newbie question

    task is to change a value in a listbox to another value,

    e.g

    3.40

    changing the price of 3.40 to 4.30 :/ if u get me!

    Well heres the code that i thought it may be but i dont no sory biggest newb here

    VB Code:
    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    2.          lstboxpric.SelectedItem = numhire.Value + lstboxpric.SelectedItem
    3.  
    4.     End Sub

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Private Sub ChangeItem(ByVal SelectedItem As Integer, ByVal NewItem As String)
    2.  
    3.         'NewItem =The new value you want to add
    4.         'SelectedItem =Index of the value you want to change
    5.  
    6.         Me.ListBox1.Items.RemoveAt(SelectedItem)
    7.         Me.ListBox1.Items.Insert(SelectedItem, NewItem)
    8.  
    9.     End Sub

    use it like this :

    VB Code:
    1. ChangeItem(Me.ListBox1.SelectedIndex, Me.TextBox1.Text)

    Make sure that there is an item selected . I left out error handling for you .

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    55
    VB Code:
    1. ChangeItem(Me.ListBox1.SelectedIndex, Me.TextBox1.Text)

    confused me

    EDIT:

    n nope the remove at function didnt work either )
    Last edited by Ezpz; Dec 20th, 2003 at 12:58 PM.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    What's wrong ?

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Ezpz
    VB Code:
    1. ChangeItem(Me.ListBox1.SelectedIndex, Me.TextBox1.Text)

    confused me

    EDIT:

    n nope the remove at function didnt work either )
    What do you mean it didn't work ? any error ?

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    55
    VB Code:
    1. ChangeItem(Me.ListBox1.SelectedIndex, Me.TextBox1.Text)

    on that line the change item bit was underlined as exception error :/

    and the other bit of code just didnt do anything no build errors or nothing, but i presume thats down to the line above not working :/ so i removed

    VB Code:
    1. Me.ListBox1.Items.Insert(SelectedItem, NewItem)

    to see if i could remove the value in list box but still it wouldnt do nothing..

    i checked to make sure it was assigned to correct button and it was :/.

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Show me how did you use it in your code ?

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    55
    Private Sub ChangeItem(ByVal SelectedItem As Integer, ByVal NewItem As String)

    'NewItem =The new value you want to add
    'SelectedItem =Index of the value you want to change

    Me.ListBox1.Items.RemoveAt(SelectedItem)
    ChangeItem(Me.ListBox1.SelectedIndex, Me.TextBox1.Text)
    Me.ListBox1.Items.Insert(SelectedItem, NewItem)

    End Sub


  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    See here how you should use it . It's VB.NET 2003 project .
    Attached Files Attached Files

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