473,769 Members | 4,470 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design Question: onChange Event populating a second list box

I'm looking for thoughts on the "correct" design for this problem (DotNet
2.0 - in winforms, but that's not so important). I've got two combo boxes
(combo1 and combo2), both are populating via database calls (using a
separate DB handler class). "combo1" contains a list of countries and is
fairly static, it can be added to but no other external events cause a
change in its population. "combo2" however is populated with a list of
options specific to a particular country. Changing the selected item in
"combo1" causes a refresh of the items listed in "combo2".

In my solution, I've extended the ComboBox for "combo2", allowing it to
contain a reference to both "combo1" and the DB handler class (they are
passed to, not created in the extended ComboBox class (note "combo1" has
also been extended to contain a ref to the DB handler class and set itself
up from it). This has allowed me to attach the code that populates "combo2"
to the OnSelectedIndex Changed event of "combo1". It produces really nice
tight code, but I've just run into an issue that makes me think that I may
not have the best design (it's close but not quite). Basically the issue is
how, if you persist the previous user selection, do you safely set up the
control(s) the second+ time that the user enters the form.

Pseudo-code of the issue:

{
InitialiseCompo nents();
...
combo1.DbHandle r = dbh1; // Populates list with contents of dbh1
combo2.DbHandle r = dbh2; // Assigns db2 to control, no list population
as no country selection yet.
combo2.CountryC omboBox = combo1; // no have implied country selection,
and populates list accordingly
...
combo1.Selected Item = UserSetting.cb1 Value; // Changes selected
country, which fires updating of list in combo2

// I'm worried about this next line!
combo2.Selected Item = UserSetting.cb2 .Value; // Should set selected
option for previously selected country
...
}

I think in the above example, the line of code that tries to set the
selected item on combo2 could be run before, or at the same time as, the
event that updates combo2's list (triggered by setting the selected item in
combo1). Is this true, do triggered events run in parallel to the code that
triggered them? If so, what's the solution? Please note in the actual
form, I've got 4 copies of this user control and adding a country or option
for a country in one of them, needs to update all the others - this is why
the extended combobox contains a reference to the db handler. The Create
function in the dbhandler fires an event that the extended combobox attaches
to. This in turn causes the list to update accordingly. I feel that I'm
not far from a MVC design pattern, and it may be the answer - but I don't
want to just end up moving the same problem out into another class.

Any thoughts, ideas or assistance would be much appreciated,

- Paul.
Jan 24 '07 #1
0 3697

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

Similar topics

10
7657
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how the onchange event isn't called when mouse wheel scrolling between A3 and B1, but it works properly when scrolling between A1 and A2. E.g. ------------------------------------------
4
11956
by: rick | last post by:
The following basic script works fine in firefox by not in IE. Can anyone spot the problem? In IE I can only delete the first line but not the lines created by javascript. Also, look at the HTML code for the first line (click the Table HTML button:)) you will fine that the code displayed is not the same as was written. "onChange" was changed to "onchange" etc. Please help. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">...
4
998
by: zdrakec | last post by:
Hello all: I have two listboxes on a webform, the user selects items from the first (which is, naturally, multi-select), and clicks a button that will copy the selected items into the second box. The code to achieve this is simple: I iterate through the first listbox' items collection, and if listbox.item(x).selected is true - if listbox1.item(x).selected then listbox2.items.add(listbox1.item(x).text)
29
3577
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this one data field - but i'm not sure) :-) Background info:
4
9825
by: tjonsek | last post by:
I have two drop down boxes on a form. One feeds the second a list options based on user selection. With the second drop down, I want code that displays dynamic text in a <div> based on whatever the user selects. So far, it doesn't seem to be firing. I am only testing the functionality because I have quite a bit of text to display depending on the users input and want to get it working first before I bother typing everything.
7
14520
by: robtyketto | last post by:
Greetings, I'm slowly building up code to do the following:- Display TWO selection option boxes (cascading). If the FIRST selection option box changes then reload the jsp using onchange event (not changing the option box value on relaod i.e. not re-running the SQL query). ONLY on initial entry should the form FIRST selection option box should be populated using JDBC SQL.
8
1485
by: sheldonlg | last post by:
I am still improving my AJAX and I ran into something that I'm not sure how to do. I will have a page called where I will have a dropdown list at the top and a large display at the bottom. The display depends upon what is currently selected in the dropdown. This is readily done via AJAX which is activated with an onchange in the dropdown list. The contents of the bottom half of the page are created in the php script which is sent back...
1
4377
by: ruds | last post by:
Hello, I have a JSP page in which HTML form elements are present. I have a drop down list named Country, when a user selects his country I want another drop down list to populate based on the first list the names of coresponding states in that country. For this I want to retrive values from database onchange event of the first drop down list. My code is: <HTML> <HEAD>
0
9591
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
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10053
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
10001
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
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
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
3
2816
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.