Combo Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manster
    New Member
    • Apr 2010
    • 5

    Combo Box

    I have a combo box that I want to refresh the data of after the save button is clicked. I know that in web developer you can just say datasource.data bind but I do not see that in vb.net. Please can someone help me out.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I'm pretty sure a combobox has a datasource property.

    Comment

    • manster
      New Member
      • Apr 2010
      • 5

      #3
      Yes, a combo box has a datasource but my question is to refresh that datasource after I saved something to the database. I saw that when I do: mycombobox.refr esh() that it repeats the data in the combobox.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        This is getting a little out of my area but...
        What if you set the datasource to null - forcing a clear - then set the datasource back to the database - forcing it to obtain the most current values?

        Comment

        • manster
          New Member
          • Apr 2010
          • 5

          #5
          Yes, I'm gonna try that tommorrow. Will post here to say if it works. Thanks anyway.

          Comment

          • bluesathish
            New Member
            • Mar 2010
            • 22

            #6
            to clear the combobox type this following code

            "comboboxname.i tems.clear();"

            try this following for refresing the datas in the combobox,
            "databind.refre sh();"

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              There is no DataBind method for the combobox.
              You should just be able to set the datasource to nothing and it should refresh. You may need to call the Update or the Refresh method for the combobox to force it to redraw on the page (as empty).

              Comment

              • manster
                New Member
                • Apr 2010
                • 5

                #8
                Combo

                OK, I promised to post here when I came right and I did not exactly come right but I saw how the first combo box was done. The person read through a dataset in a loop and did: combobox1.items .add("datacolum n"). I did want to change it to a datasource but still has to learn how they work but I think to set the datasource to nothing and give it again sounds good. in vb.net's comboboxes or any databound controls you cannot use databind. I am busy doing other combo boxes with datasources and will come tell of my successes. Thanks for your posts here and I hope I will be able to help any of you soon.

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  If you used the Add method to add the items to the ComboBox then you have to use the Remove method to remove them. Setting the datasource to nothing will not work in this case.

                  Comment

                  • manster
                    New Member
                    • Apr 2010
                    • 5

                    #10
                    Yes, you are right and now I am investigating both options to see which will be the best. The additem or the datasource. Thanks for the interest.

                    Comment

                    • shekoasinger
                      New Member
                      • May 2010
                      • 4

                      #11
                      Try ComboBox1.Updat e()
                      I dont know If it works.

                      Comment

                      • bluesathish
                        New Member
                        • Mar 2010
                        • 22

                        #12
                        Originally posted by Frinavale
                        There is no DataBind method for the combobox.
                        You should just be able to set the datasource to nothing and it should refresh. You may need to call the Update or the Refresh method for the combobox to force it to redraw on the page (as empty).
                        ya you're correct, we cant do databind.refres h().

                        Comment

                        • mfaisalwarraich
                          New Member
                          • Oct 2007
                          • 194

                          #13
                          Hi,

                          if you are adding items into the combobox using the database i recommend you the following code:
                          Code:
                          With comboBox1
                            .DataSource = Me.YourDataSetName.YourTableName
                            .DisplayMember = Me.YourDataSetName.YourTableName.Columns(1).ColumnName
                            .ValueMember = Me.YourDataSetName.YourTableName.Columns(0).ColumnName
                          
                          
                          End With
                          This will add items into your combobox. After that you can set the datasource to nothing and then select datasource again. Here is the code:
                          Code:
                                          comboBox1.DataSource = null
                                          comboBox1.Items.Clear()
                                          comboBox1.DataSource = Me.YourDataSetName.YourTableName
                          i think this may help you.

                          Comment

                          Working...