Results 1 to 6 of 6

Thread: Adding items to a list/combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    6

    Question

    Ok I am new to VB and have been able to figure out a few things that I need to do AND most of what I want to do is probably pretty basic compared to most of you but I'm gonna ask anyway! So that being said even a link to the basic stuff would be appreciated.

    I have some combo/list boxes on my project and would like to have the ability to have the user add text and remove text to and from the list. I must have come close to the correct code but the best I could do was everytime you typed in a letter another blank space came up on the list

    I have really no backgroung in programming but I do find it quite interesting (to say the least).

    So.... anyone interested in adding something that my peanut cant quite understand?

    I thank you in advance for anyone that will take the time to help me out.

    I really have spent a while looking around before I decided to post and couldnt find quite what I'm looking for.

    First post, first question...more to come I'm sure.
    So....I'm new

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    well you could have a textbox and a 2 command buttons and then have this code

    Code:
    'to add items
    Private Sub Command1_Click()
       List1.AddItem Text1.Text
       'or
       Combo1.AddItem Text1.Text
    End Sub
    
    'to remove individual items
    Private Sub Command2_Click()
       List1.RemoveItem List1.SelectedItem
    End Sub
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    6

    Smile

    Wow your quick. Thanks. However I guess what I want is a little more complicated than that (surely not much).
    In my usual haste I forgot to mention that I have the word "OTHER" in the list box and was hoping that when it was selected that I could have a inputbox open up and give the choice to add the item to the list.
    So....I'm new

  4. #4
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258


    Code:
    Dim Message, Title, Default ,retval
    If List1.Text="OTHER" then 
    Message = "Enter Item to add"   ' Set prompt.
    Title = "Adding an Item" ' Set title.
    Default = "SomeItem"   ' Set default.
    ' Display message, title, and default value.
    MyValue = InputBox(Message, Title, Default)
    List1.additem MyValue
    End If
    This is untested but should work put it in the mouse up event of your listbox


    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    6

    Smile

    Thank you both very much. I'll scurry right off and try it.

    Ok I guess I missed something probably in the "mouse up event of your listbox".

    This is exactly what I have,

    Private Sub Combo1_Change()
    Dim Message, Title, Default, retval
    If Combo1.Text = "OTHER" Then
    Message = "Enter Item to add" ' Set prompt.
    Title = "Adding an Item" ' Set title.
    Default = "SomeItem" ' Set default.
    ' Display message, title, and default value.
    MyValue = InputBox(Message, Title, Default)
    List1.AddItem MyValue
    End If

    End Sub

    Your quite welcome to slap me if I have missed something totally obvious to you.

    [Edited by Buckaroo on 11-05-2000 at 02:28 PM]
    So....I'm new

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    6

    Wink

    Well now after my usual fumblings and regrets from my last post I have actually managed to get it to work...sort of.
    Here is what I have so far and yes it does add to the combo box I have, however once the program is shut down and restarted it is gone. Must be very close to what I want but the final solution escapes me at this moment.

    Private Sub Combo1_Click()
    Dim Message, Title, Default, retval, MyValue
    If Combo1.Text = "OTHER" Then
    Message = "Enter Item to add" ' Set prompt.
    Title = "Adding an Item" ' Set title.
    Default = "New Product" ' Set default.
    ' Display message, title, and default value.
    MyValue = InputBox(Message, Title, Default)
    Combo1.AddItem MyValue
    End If
    End Sub

    Any other suggestion from the great people around here would be kindly accepted

    [Edited by Buckaroo on 11-05-2000 at 08:14 PM]
    So....I'm new

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