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. How to refresh a combobox in another form after the values of the combo have been updated?

How to refresh a combobox in another form after the values of the combo have been updated?

Scheduled Pinned Locked Moved Visual Basic
questioncomhelptutorial
4 Posts 2 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.
  • R Offline
    R Offline
    rprateek
    wrote on last edited by
    #1

    I checked in msdn forum as well but there is one thread still pending not getting the answer of the similar problem, so I thought of posting it here. Lets get the picture of the problem first. 1. I have a form called cat where I have one field called CatName where I save the data. 2 I have another form where I have got Combo box where I load cats when form loads. Now question is imagine I have more than 40 fields in the form 2 where user filled up 39 fields but when he came to cats combo box then he found that one cat is not there so he opens cat form to add the new cat in it. Then how can i acheive this without opening a new form. Here is what i have tried so far this is the sub where i load cats in combobox: Public Sub LoadCats(ByVal cboCats As ComboBox) Dim objdb As New clsObjDB Dim ds As New DataSet Dim str As String cboCats.Items.Clear() str = "Select * from cat order by catID desc" ds = objdb.getDataset(str) Dim dt As DataTable dt = ds.Tables(0) For Each row As DataRow In dt.Rows cboCats.ValueMember = row("CatID") cboCats.Items.Add(row("CatName")) Next End Sub Now in cat I tried Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click Dim objdb As New clsObjDB Dim str As String If txtCatName.Text.Trim = "" Then MessageBox.Show("Enter the Cat Name") txtCatName.Focus() objdb = Nothing Exit Sub End If str = "Insert into cat(CatName)values('" & txtCatName.Text & "')" objdb.ExecuteQuery(str) MessageBox.Show("Success") '***************************************** 'Now my save is finished so over here i tried loading of cbocats Dim frm As dog '********* Here is the problem I can't do new here because the user wants to stay on the same page he was working on. LoadCats(frm.cboCats) Me.txtCatName.Text = "" End Sub Hope you guys get the point, I am very poor in explaining these sort of things.... Thanks in advance

    Blog for Programmers http://www.rprateek.blogspot.com

    A R 2 Replies Last reply
    0
    • R rprateek

      I checked in msdn forum as well but there is one thread still pending not getting the answer of the similar problem, so I thought of posting it here. Lets get the picture of the problem first. 1. I have a form called cat where I have one field called CatName where I save the data. 2 I have another form where I have got Combo box where I load cats when form loads. Now question is imagine I have more than 40 fields in the form 2 where user filled up 39 fields but when he came to cats combo box then he found that one cat is not there so he opens cat form to add the new cat in it. Then how can i acheive this without opening a new form. Here is what i have tried so far this is the sub where i load cats in combobox: Public Sub LoadCats(ByVal cboCats As ComboBox) Dim objdb As New clsObjDB Dim ds As New DataSet Dim str As String cboCats.Items.Clear() str = "Select * from cat order by catID desc" ds = objdb.getDataset(str) Dim dt As DataTable dt = ds.Tables(0) For Each row As DataRow In dt.Rows cboCats.ValueMember = row("CatID") cboCats.Items.Add(row("CatName")) Next End Sub Now in cat I tried Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click Dim objdb As New clsObjDB Dim str As String If txtCatName.Text.Trim = "" Then MessageBox.Show("Enter the Cat Name") txtCatName.Focus() objdb = Nothing Exit Sub End If str = "Insert into cat(CatName)values('" & txtCatName.Text & "')" objdb.ExecuteQuery(str) MessageBox.Show("Success") '***************************************** 'Now my save is finished so over here i tried loading of cbocats Dim frm As dog '********* Here is the problem I can't do new here because the user wants to stay on the same page he was working on. LoadCats(frm.cboCats) Me.txtCatName.Text = "" End Sub Hope you guys get the point, I am very poor in explaining these sort of things.... Thanks in advance

      Blog for Programmers http://www.rprateek.blogspot.com

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

      rprateek wrote:

      Dim dt As DataTable dt = ds.Tables(0) For Each row As DataRow In dt.Rows cboCats.ValueMember = row("CatID") cboCats.Items.Add(row("CatName")) Next

      Instead of adding each cat to combobox Why dont you set datasource, displaymember and valuemember? If you are using a different form to add, update and delete from your cats catalog, just call that form from your cat form (as you are doing now) using showdialog and after that, just call your loadcats again to refill combobox I didnt really understand what you are doing, but this should work

      Alexei Rodriguez

      R 1 Reply Last reply
      0
      • A AlexeiXX3

        rprateek wrote:

        Dim dt As DataTable dt = ds.Tables(0) For Each row As DataRow In dt.Rows cboCats.ValueMember = row("CatID") cboCats.Items.Add(row("CatName")) Next

        Instead of adding each cat to combobox Why dont you set datasource, displaymember and valuemember? If you are using a different form to add, update and delete from your cats catalog, just call that form from your cat form (as you are doing now) using showdialog and after that, just call your loadcats again to refill combobox I didnt really understand what you are doing, but this should work

        Alexei Rodriguez

        R Offline
        R Offline
        rprateek
        wrote on last edited by
        #3

        ya i understand your point but i didn't mean that.. you can try it yourself I just want is one form for eg form1 open where we have cbobox where we have cats. now as per your advice i did datasource and data member . ok i opened the dialog box to insert new cat. Now how would you load the cats in the same form called form1 that is open. where you have to do following to load cats LoadCats(frm.cboCats) but if you don't do frm= new frmCats then it will show error ..... so how to overcome this.?????????

        Blog for Programmers http://www.rprateek.blogspot.com

        1 Reply Last reply
        0
        • R rprateek

          I checked in msdn forum as well but there is one thread still pending not getting the answer of the similar problem, so I thought of posting it here. Lets get the picture of the problem first. 1. I have a form called cat where I have one field called CatName where I save the data. 2 I have another form where I have got Combo box where I load cats when form loads. Now question is imagine I have more than 40 fields in the form 2 where user filled up 39 fields but when he came to cats combo box then he found that one cat is not there so he opens cat form to add the new cat in it. Then how can i acheive this without opening a new form. Here is what i have tried so far this is the sub where i load cats in combobox: Public Sub LoadCats(ByVal cboCats As ComboBox) Dim objdb As New clsObjDB Dim ds As New DataSet Dim str As String cboCats.Items.Clear() str = "Select * from cat order by catID desc" ds = objdb.getDataset(str) Dim dt As DataTable dt = ds.Tables(0) For Each row As DataRow In dt.Rows cboCats.ValueMember = row("CatID") cboCats.Items.Add(row("CatName")) Next End Sub Now in cat I tried Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click Dim objdb As New clsObjDB Dim str As String If txtCatName.Text.Trim = "" Then MessageBox.Show("Enter the Cat Name") txtCatName.Focus() objdb = Nothing Exit Sub End If str = "Insert into cat(CatName)values('" & txtCatName.Text & "')" objdb.ExecuteQuery(str) MessageBox.Show("Success") '***************************************** 'Now my save is finished so over here i tried loading of cbocats Dim frm As dog '********* Here is the problem I can't do new here because the user wants to stay on the same page he was working on. LoadCats(frm.cboCats) Me.txtCatName.Text = "" End Sub Hope you guys get the point, I am very poor in explaining these sort of things.... Thanks in advance

          Blog for Programmers http://www.rprateek.blogspot.com

          R Offline
          R Offline
          rprateek
          wrote on last edited by
          #4

          hey guys please have a look into this

          Blog for Programmers http://www.rprateek.blogspot.com

          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