473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

saving values programmically to cbo

23
Hi
I can add values to a cbo values list by cbo.additem but when I close the form and reopen it it is gone. How do I save it to the value list? Thanks
Nov 18 '07 #1
4 1996
ADezii
8,834 Expert 8TB
Hi
I can add values to a cbo values list by cbo.additem but when I close the form and reopen it it is gone. How do I save it to the value list? Thanks
Use the Open() Event of the Form to programmatically add Items to the Combo Box via the AddItem Method.
Nov 19 '07 #2
NeoPa
32,556 Expert Mod 16PB
In short you don't.
A static list (of values) is just that. If it is a design change you need (you realised later that a required item was missing from your list), then you open the form in design mode and update your list.
If it is a dynamic list to start with, then it is either session level dynamic (not in your case clearly) in which case what you already have is fine, or it is dynamic across sessions, in which case a static list is not the right way to handle this. In that case a table based ComboBox should be used. Doing dynamic updates using a static list (This is in Access after all) is like having a dog and barking yourself.
Nov 19 '07 #3
missinglinq
3,532 Expert 2GB
ADezii's method using AddItem works if you want to do something such as loading the available printers each time a form cranks up, but if you have a cbo with a list of vegetables, and after tasting broccoli you just have to add it to the list, it won't do! As NeoPa has so elegantly put it, a table/query based combobox is really the only sane way to go in this situation! It not only allows items to be added to the combobox which will carry over into future sessions, it allows items to be removed from the control as well!

A while back I did write a hack for adding items permanently to a combobox, and can probably find a copy for you (although it may be tomorrow before I get around to finding it; it's on a "retired" PC and I'll have to dig it out) if you absolutely have to go this route, but it's convoluted and probably more trouble than it's worth! It involves


  1. Opening a second, dummy, form, passing it the new item using OpenArgs
  2. Closing the first form
  3. In the second form, opening the first form in Design Mode
  4. Adding the item to the cobobox
  5. Closing the first form
  6. Closing the second form
  7. Re-opening the first form, with the new item in the cbo
As I said, it's not pretty! Let me know; I'll try to locate it! But give some thought to using a table/query based combobox!

Welcome to TheScripts!

Linq ;0)>
Nov 19 '07 #4
ADezii
8,834 Expert 8TB
ADezii's method using AddItem works if you want to do something such as loading the available printers each time a form cranks up, but if you have a cbo with a list of vegetables, and after tasting broccoli you just have to add it to the list, it won't do! As NeoPa has so elegantly put it, a table/query based combobox is really the only sane way to go in this situation! It not only allows items to be added to the combobox which will carry over into future sessions, it allows items to be removed from the control as well!

A while back I did write a hack for adding items permanently to a combobox, and can probably find a copy for you (although it may be tomorrow before I get around to finding it; it's on a "retired" PC and I'll have to dig it out) if you absolutely have to go this route, but it's convoluted and probably more trouble than it's worth! It involves


  1. Opening a second, dummy, form, passing it the new item using OpenArgs
  2. Closing the first form
  3. In the second form, opening the first form in Design Mode
  4. Adding the item to the cobobox
  5. Closing the first form
  6. Closing the second form
  7. Re-opening the first form, with the new item in the cbo
As I said, it's not pretty! Let me know; I'll try to locate it! But give some thought to using a table/query based combobox!

Welcome to TheScripts!

Linq ;0)>
There may be cases where you would not want to 'expose' the RowSource of a Combo Box especially with a Table or Query. A Hybrid Dynamic/Static Value List can persist and be written directly to the System Registry as a Delimited String. A simple Algorithm can Add, Remove, Modify, Populate certain elements in the List while the entire process remains Transparent to the User. I know it's a little extreme, but I have used this concept before when it was imperative that the Source for the Combo Data be totally inaccessible.
Nov 19 '07 #5

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

Similar topics

6
by: Lloyd | last post by:
How do you make a textbox enabled or disabled ??? i have tried Textbox.disable or enable but the controls apparently dont have this property programmically ???
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
9
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all...
1
by: Sebastian Santacroe | last post by:
Hello, I've got a datagrid with two columns and no data. I want to add data programmically (from DB). When I try to use sintax like: dataset.Tables("Department").Rows(0).Item("Percentage Used")...
2
by: Agnes | last post by:
I set my datagrid's datasource programmically . However , as the form load, I found that every column width is the same, Question 1) How can i adjust it programmically ??? Question 2) I need to do...
6
by: NutsAboutVB | last post by:
Hello, I am a .NET programmer and I have a JPEG image file (from digital camera) of about 109 KB's in size, when I open it and save it (without making any alterations at all, just going to File...
3
by: Franky | last post by:
I'm trying to learn about the MenuStrip and the ContextStrip. I use Google and get an unbelievable number of hits but can't seem to find out the answer to one question. All the items on my...
2
by: tee | last post by:
Hi, How do i sort datagridview programmically, current i have the following code but i keep get the error saying "DataGridView control must be bound to an IBindingList object to be sorted.", ...
4
by: cdawson2000 | last post by:
Hello Gurus, I have a movie that is composed of a picture and 5 buttons below it. When the user clicks button1, a lighting effect occurs, then the image is changed to image1. When the user clicks...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.