Results 1 to 6 of 6

Thread: Vb Combobox problem adding new item

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    2

    Unhappy


    Can anyone Please help me . How can I in Runtime add
    new item in combobox and have it permanently added
    to the Combobox List??? When I add on the top it is removed when program stops. Thank you in advance.

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84
    how about adding your items from a textfile into your combobox and before the program is closed, storing then back into you file

    I can send you an example by email

  3. #3
    Guest
    Here is an example, add a ComboBox called Combo1 and a CommandButton called Command1.


    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        AddComboBoxItem Combo1, "Item" & Val(Rnd * 100)
    End Sub
    
    
    Private Sub AddComboBoxItem(cbo As ComboBox, ByVal sItem As String)
        Dim iFileNummer As Integer
        Dim sCurrentitem As String
        
        'open file
        iFileNummer = FreeFile
        Open App.Path & "\" & App.ProductName & "_" & cbo.Name & ".dat" For Append As iFileNummer
        
        'Add item
        Print #iFileNummer, sItem
        
        'Close file
        Close #iFileNummer
        
        'Remeber what item we have currently selected
        sCurrentitem = cbo.Text
        
        'Re-read the values
        ReadComboBox cbo
        
        'Set item back to the one we had selected
        On Error Resume Next
        cbo.Text = sCurrentitem
    End Sub
    
    Private Sub ReadComboBox(cbo As ComboBox)
        Dim iFileNummer As Integer
        Dim sItem As String
        
        'Clear ComboBox
        cbo.Clear
        
        'Open File
        iFileNummer = FreeFile
        Open App.Path & "\" & App.ProductName & "_" & cbo.Name & ".dat" For Input As iFileNummer
        
        'Read items
        Do Until EOF(iFileNummer)
            Line Input #iFileNummer, sItem
            
            'Add item to combobox
            cbo.AddItem sItem
        Loop
        
        'Close File
        Close iFileNummer
    End Sub
    
    Private Sub Form_Load()
        ReadComboBox Combo1
    End Sub

  4. #4

  5. #5
    Guest
    Originally posted by MartinLiss
    If you are willing to add a command button to your form, as has been suggested, all you need to do is this[...]
    [/code]
    Erm in his original post he posted this:
    have it permanently added
    to the Combobox List??? When I add on the top it is removed when program stops.



  6. #6

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