By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,960 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,960 IT Pros & Developers. It's quick & easy.

Combo Box

P: 5
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.databind but I do not see that in Please can someone help me out.
Apr 16 '10 #1
Share this Question
Share on Google+
12 Replies

Expert 2.5K+
P: 3,525
I'm pretty sure a combobox has a datasource property.
Apr 17 '10 #2

P: 5
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.refresh() that it repeats the data in the combobox.
Apr 17 '10 #3

Expert 2.5K+
P: 3,525
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?
Apr 17 '10 #4

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

P: 22
to clear the combobox type this following code


try this following for refresing the datas in the combobox,
Apr 19 '10 #6

Expert Mod 5K+
P: 9,731
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).
Apr 27 '10 #7

P: 5
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("datacolumn"). 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'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.
Apr 29 '10 #8

Expert Mod 5K+
P: 9,731
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.
Apr 29 '10 #9

P: 5
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.
Apr 29 '10 #10

P: 4
Try ComboBox1.Update()
I dont know If it works.
May 8 '10 #11

P: 22
ya you're correct, we cant do databind.refresh().
May 13 '10 #12

P: 194

if you are adding items into the combobox using the database i recommend you the following code:
Expand|Select|Wrap|Line Numbers
  1. With comboBox1
  2.   .DataSource = Me.YourDataSetName.YourTableName
  3.   .DisplayMember = Me.YourDataSetName.YourTableName.Columns(1).ColumnName
  4.   .ValueMember = Me.YourDataSetName.YourTableName.Columns(0).ColumnName
  7. 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:
Expand|Select|Wrap|Line Numbers
  1.                 comboBox1.DataSource = null
  2.                 comboBox1.Items.Clear()
  3.                 comboBox1.DataSource = Me.YourDataSetName.YourTableName
i think this may help you.
May 14 '10 #13

Post your reply

Sign in to post your reply or Sign up for a free account.