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. C#
  4. Refresh comboxbox in form1 after form2 is closed

Refresh comboxbox in form1 after form2 is closed

Scheduled Pinned Locked Moved C#
csharpasp-netdatabasetutorialannouncement
7 Posts 4 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.
  • M Offline
    M Offline
    misCafe
    wrote on last edited by
    #1

    Dear developers, I am coding a very small project for my study. I want to refresh form1 after form2 is closed. For example, I open form1 and click one button to open form2 and in form2 I can insert data to the database (ex : tblItem). In addition, combobox in form1 retrieves data from the database (tblItem) too. So, after inserting data from form2 and when I close the form2, I want the comboxbox in form1 refresh to retrieve the last update of tblItem data. Here is my code to open form2 form2 frmitem = new form2(); frmitem.ShowDialog(); Please advise, thanks. Visoth

    Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

    K 1 Reply Last reply
    0
    • M misCafe

      Dear developers, I am coding a very small project for my study. I want to refresh form1 after form2 is closed. For example, I open form1 and click one button to open form2 and in form2 I can insert data to the database (ex : tblItem). In addition, combobox in form1 retrieves data from the database (tblItem) too. So, after inserting data from form2 and when I close the form2, I want the comboxbox in form1 refresh to retrieve the last update of tblItem data. Here is my code to open form2 form2 frmitem = new form2(); frmitem.ShowDialog(); Please advise, thanks. Visoth

      Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

      K Offline
      K Offline
      Kubajzz
      wrote on last edited by
      #2

      You can paste your code directly behind the ShowDialog() row. If you call the ShowDialog() function, the main form will "sleep" until the dialog window is closed. For example, if you call ShowDialog(), and on the next line you call Messagebox.Show(), the messagebox will be shown as soon as the dialog window is closed. So your code might look like this:

      form2 frmitem = new form2();
      frmitem.ShowDialog();

      UpdateMyComboBox(); // this function will be called as soon as the dialog window is closed

      M R 2 Replies Last reply
      0
      • K Kubajzz

        You can paste your code directly behind the ShowDialog() row. If you call the ShowDialog() function, the main form will "sleep" until the dialog window is closed. For example, if you call ShowDialog(), and on the next line you call Messagebox.Show(), the messagebox will be shown as soon as the dialog window is closed. So your code might look like this:

        form2 frmitem = new form2();
        frmitem.ShowDialog();

        UpdateMyComboBox(); // this function will be called as soon as the dialog window is closed

        M Offline
        M Offline
        misCafe
        wrote on last edited by
        #3

        Sorry, can give explain me more detail than this? :)

        Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

        K 1 Reply Last reply
        0
        • M misCafe

          Sorry, can give explain me more detail than this? :)

          Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

          K Offline
          K Offline
          Kubajzz
          wrote on last edited by
          #4

          It's not possible to explain it in more detail, because it's just too simple... Maybe my explanation was not clear enough, I'll try once more. You asked how to refresh a combobox after a child form has closed. The answer is simple - the code that refreshes the combobox should be right behind the form.ShowDialog() line. It will be executed as soon as the child form is closed, and that's what you want.

          M 1 Reply Last reply
          0
          • K Kubajzz

            It's not possible to explain it in more detail, because it's just too simple... Maybe my explanation was not clear enough, I'll try once more. You asked how to refresh a combobox after a child form has closed. The answer is simple - the code that refreshes the combobox should be right behind the form.ShowDialog() line. It will be executed as soon as the child form is closed, and that's what you want.

            M Offline
            M Offline
            misCafe
            wrote on last edited by
            #5

            private void lkl_additem_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) //form1 { //Open form2 from form1 form2 frmitem = new form2(); frmitem.ShowDialog(); this.cbo_itemname.Refresh(); // This is a combobox in form1 which I wanna update when form2 closes. } Is the code like this??? However, it doesn't work. :(

            Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

            T 1 Reply Last reply
            0
            • M misCafe

              private void lkl_additem_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) //form1 { //Open form2 from form1 form2 frmitem = new form2(); frmitem.ShowDialog(); this.cbo_itemname.Refresh(); // This is a combobox in form1 which I wanna update when form2 closes. } Is the code like this??? However, it doesn't work. :(

              Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner

              T Offline
              T Offline
              Tash18
              wrote on last edited by
              #6

              Hi, Actually he wants you to place the code that refreshes the combobox just before the following line in ur code..

              frmitem.ShowDialog();

              Hope u understand.... Regards, Tash

              1 Reply Last reply
              0
              • K Kubajzz

                You can paste your code directly behind the ShowDialog() row. If you call the ShowDialog() function, the main form will "sleep" until the dialog window is closed. For example, if you call ShowDialog(), and on the next line you call Messagebox.Show(), the messagebox will be shown as soon as the dialog window is closed. So your code might look like this:

                form2 frmitem = new form2();
                frmitem.ShowDialog();

                UpdateMyComboBox(); // this function will be called as soon as the dialog window is closed

                R Offline
                R Offline
                Rajeshwari Laxmanan
                wrote on last edited by
                #7

                Thnx a ton. Ur solution is the best :-D

                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