Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Addint items to a combobox

Addint items to a combobox

Scheduled Pinned Locked Moved Visual Basic
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave McCool
    wrote on last edited by
    #1

    I have a combo box on form FrmFinance and it has lots of values and a "Other" selection. If you select it, a dialog window opens, Dialog1. What I want is that on Dialog1 form there is a textbox called txtMake and when you press OK btnOK on the dialog1 form, the item gets added to cmbmake (combo box) on FrmFinance. I don't want any values removed from the combobox, just add what is in the textbox when you press OK Any ideas?

    In the end we're all just the same

    A 1 Reply Last reply
    0
    • D Dave McCool

      I have a combo box on form FrmFinance and it has lots of values and a "Other" selection. If you select it, a dialog window opens, Dialog1. What I want is that on Dialog1 form there is a textbox called txtMake and when you press OK btnOK on the dialog1 form, the item gets added to cmbmake (combo box) on FrmFinance. I don't want any values removed from the combobox, just add what is in the textbox when you press OK Any ideas?

      In the end we're all just the same

      A Offline
      A Offline
      AliAmjad
      wrote on last edited by
      #2

      At Last found the solution to this problem previously I was also facing somewhat similar problem here is the solution which worked for me. In your form2 declare a Class level variable of form type e.g.

      Dim oForm as Form

      now in the Load event of form2 just make this equal to the 'ActiveForm' property of frmFinance e.g.

      oForm = frmFinance.ActiveForm

      Now just enter the following code in the Button Click event handler or in whatever event you want to use in order to add items to the Combobox e.g.

      Private Sub btnOK\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
      
          CType(oForm, frmFinance).cboMake.Items.Add(Me.txtMake.Text)
      
      End Sub
      

      As it helped me I hope it help you too... Good Luck !

      AliAmjad(MCP) First make it Run THEN make it Run Fast!

      L D 2 Replies Last reply
      0
      • A AliAmjad

        At Last found the solution to this problem previously I was also facing somewhat similar problem here is the solution which worked for me. In your form2 declare a Class level variable of form type e.g.

        Dim oForm as Form

        now in the Load event of form2 just make this equal to the 'ActiveForm' property of frmFinance e.g.

        oForm = frmFinance.ActiveForm

        Now just enter the following code in the Button Click event handler or in whatever event you want to use in order to add items to the Combobox e.g.

        Private Sub btnOK\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        
            CType(oForm, frmFinance).cboMake.Items.Add(Me.txtMake.Text)
        
        End Sub
        

        As it helped me I hope it help you too... Good Luck !

        AliAmjad(MCP) First make it Run THEN make it Run Fast!

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        OK, but maybe you also want: - to make sure the value is not already present; - sort the values; - remove some when there are too many values. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


        1 Reply Last reply
        0
        • A AliAmjad

          At Last found the solution to this problem previously I was also facing somewhat similar problem here is the solution which worked for me. In your form2 declare a Class level variable of form type e.g.

          Dim oForm as Form

          now in the Load event of form2 just make this equal to the 'ActiveForm' property of frmFinance e.g.

          oForm = frmFinance.ActiveForm

          Now just enter the following code in the Button Click event handler or in whatever event you want to use in order to add items to the Combobox e.g.

          Private Sub btnOK\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
          
              CType(oForm, frmFinance).cboMake.Items.Add(Me.txtMake.Text)
          
          End Sub
          

          As it helped me I hope it help you too... Good Luck !

          AliAmjad(MCP) First make it Run THEN make it Run Fast!

          D Offline
          D Offline
          Dave McCool
          wrote on last edited by
          #4

          I got that to work, just changed "Dim oForm as Form" to "Public oForm as Form", thanks. Now how would I remove all items I added to combo box without removing all items? Also, when you click button, I want the combobox to focus on the new added item

          In the end we're all just the same

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups