Results 1 to 4 of 4

Thread: Updating a combo box immediately

  1. #1
    Roman_Candle is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Jan 2005
    Posts
    10
    Reputation
    104

    Updating a combo box immediately

    i have a combo box on a form.
    when you select an item from it the rest of the form is populated(ie a search function)

    i can also add a new record on the form.
    what i want is for the new record i add to appear in the combo box straight away.

    to originally populate the combo box i have been using a block of code i place in the form load.so i decided to take this block of code and place in a sub procedure and call it when i add a record instead.however it doesnt seem to update straight away unless i exit the form and then go back into it!

    am i going about this the right way?

  2. #2
    SpiritualMachine is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Feb 2005
    Posts
    12
    Reputation
    103
    What code are you using to update it?

    Couldn't you use ComboBox1.Items.Add(.... or something similar?

  3. #3
    Roman_Candle is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Jan 2005
    Posts
    10
    Reputation
    104

    current code

    this is what i have been using to populate the combo box from form load.but i decided to put it into a sub procedure to call it in the INSERT statement.


    Code:
    PublicSub UpdateComboBox1()
     
    Dim conn = New OleDbConnection(conn1)
     
    Dim ds1 AsNew DataSet()
     
    Dim dt As DataTable
     
    Dim dr As DataRow
     
    da1.Fill(ds1)
     
    cboYearlyStuff.Items.Clear()
     
     
     
    'Repeat for each table in the DataSet collection.
     
    ForEach dt In ds1.Tables
     
    'Repeat for each row in the table.
     
    ForEach dr In dt.Rows
     
    Dim strMyJoin AsString
     
    strMyJoin = (dr("Yearly_ID")) & " - " & (dr("TheYear")) & " - " & (dr("MyClass"))
     
    cboYearlyStuff.Items.Add(strPupilJoin)
     
    Next
     
    Next
     
    EndSub


    it works when i call it from form load,but wont work for subsequent "callings"

    Code:
     
    Private
    Code:
    Sub YearlyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
    UpdateComboBox1()
     
    EndSub


  4. #4
    SpiritualMachine is offline VB.NET Forum Newbie
    .NET Framework
    Join Date
    Feb 2005
    Posts
    12
    Reputation
    103
    Is there a close method that should be used for the database connection?

Bookmarks

Posting Permissions

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