473,785 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preventing items from being added automatically to a comboBox

Greetings!

In order to keep better track a form with several combo-boxes, I've
subclassed the ones that need to change in response to events on other
controls on the form. An example of a subclassed combo box:

<code>
Public Class byte13ComboBox
Inherits System.Windows. Forms.ComboBox
Private comboItems() As String = {"a (Numbered)", _
"b (Unnumbered)", _
"c (Numbering varies)", _
"n (Not applicable)"}
Sub New()
MyBase.New()

For Each j As Object In Items
Items.Remove(j)
Next

For Each i As String In comboItems
Items.Add(i)
Next

SelectedIndex = 0
' The user must choose an item already in the list.
DropDownStyle = ComboBoxStyle.D ropDownList
End Sub

'...Various custom functions removed for clarity

End Class
</code>

The problem is that even though I empty the Items Collection each time,
the items build up: the first time I run the program, the Combo works
properly. The next time I run it, it has eight options, the next time
twelve, etc.

When I look at the Items property on the Forms view, I can see that
these items are being added cumulatively there. Emptying it on the
Forms view resets it, but the list items immediately start accumulating
again.

How do I prevent VB from automatically adding extra items? Or is there
an event I should be using to reset the ComboBox, rather than doing it
in the constructor?

Thanks!

Nov 21 '05 #1
3 1490
Why don't you just do:

'ComboBox1.Item s.Clear()'?
Nov 21 '05 #2
Crouchie1998,

I tried that, and it didn't work, so I added the removal code.

But I later realized that wasn't the problem, because the Items were
being added back in *after* I cleared it, but I had forgotten to change
it back to clear(). So the problem still remains: even if I empty the
Items in the constructor, they still build up cumulatively each time I
run the form.

Thanks,

Linda

Nov 21 '05 #3
Hi,

I got around the problem by pulling the code out of the contsructor,
and putting it into a "Reset()" function which I call explicitly on
Form_Load. Handling it in the constructor would have been more elegant,
but this works too.

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2220
by: Tom | last post by:
Using AccessXP - Access2000 In my application, when an order is entered, inventory is automatically adjusted, a pull list is created, items are pulled to fill the order, and the order is packaged for shippment. The order is then held pending payment and finally shipped when payment is received. Sometimes prior to shipment the customer calls and wants to change one or more items, wants to change the quantity of one or more items or wants...
3
3083
by: Brian Henry | last post by:
Is there anyway to prevent the white box that drops down when you do a combobox dropdown from showing? I am trying to make a custom combobox which requires showing a custom form in its place, but the white box shows up still ontop of the new form that is taking its palce even though there is no items in the white box. Any windows messages or anything you can trap or whatnot? thanks!
9
7322
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the combobox, but I can't find anything that will let me do that. - Don
3
6978
by: Stuart | last post by:
I am using Visual Basic 2005. I have created a two dimensional ArrayList named aSystem that is populated as follows:- aSystem.Add(New PickList(0, "Undefined")) aSystem.Add(New PickList(-1, "Standard UTM")) aSystem.Add(New PickList(-2, "UTM-NAD83")) aSystem.Add(New PickList(-3, "UTM-NAD27"))
3
1847
by: Lee | last post by:
Hi, I am wondering whether it is easily achievable to create a custom combo box control which contains certain items preloaded. Basically I have a form which will contains several combos, each of which will contain the same items. Rather then iterating through each combo as part of the form load I wanted the control to automatically contain the items.
6
2486
by: active | last post by:
I need a combobox where the items are typed as string - not object. And another where the items are from a class I generated. Can one make such comboboxes from System.Windows.Forms.ComboBox? If that is not practical I appreciate you telling me that? Thanks in advance
3
4949
by: ags5406 | last post by:
I've a listbox that I add items to at different points in the code. It's height is such that only about 6 items can be displayed vertically. The first item added shows up in the top line, then the second item in the second line, etc. After 6 items have been added, the vertical scroll bar appears and new items continue to be added, but until the user actually moves the scrollbar down the box displays only the first 6 items. What I'd...
5
18768
by: Kevinp | last post by:
I've spent the last four hours Google searching for a way to disable items in a Combobox. I found one example in C++ which I can't get to work and another in C# that I couldn't get to work either. Does anyone have some good code for an owner-drawn combobox?
1
2672
by: madhuri736 | last post by:
i have taken one combobox in form1, another in form2. when i want to add an item permanently in combobox in form1 it should automatically added in the form2's combobox permanently and at the same time it should be added into the database(ms access) also.
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8978
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.