473,842 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bound Combo Box Problems

I have what I think should be a simple question regarding a bound combo box.
My first table is Dealers:
DealerID - primary key
DealerName
BillToLocation

My second table is Locations:
LocationID - primary key
LocationDescrip tion
DealerID - DealerID of the dealer this location belongs to

I want a bound combo box that when on a dealer record it displays the
LocationDescrip tion for the dealer record's BillToLocation. But I want the
user to be able to change the BillToLocation to one of the dealers locations
in the Locations table.

At this point I have a combo box that shows only that Dealer's locations in
the drop down list, will update the BillToLocation when it's selected and
saved, but unfortunately it doesn't display correctly as I navigate through
the records using bmDealers.Posit ion++ or bmDealers.Posit ion--;
Interestingly enough, if I load a particular dealer record, it displays the
correct LocationDescrip tion, but if navigate away and then back, it gets out
of sync.

Could someone give me some guidance as to what I'm doing wrong? Thank you.

Here is the binding code:
dsCoinTableAdap ters.DealersTab leAdapter daDealers = new
dsCoinTableAdap ters.DealersTab leAdapter();
dtDealers = ds.Dealers;
daDealers.Fill( dtDealers);

dsCoinTableAdap ters.LocationsT ableAdapter daLocations = new
dsCoinTableAdap ters.LocationsT ableAdapter();
dtLocations = ds.Locations;
daLocations.Fil l(dtLocations);

DataColumn pdc = dtDealers.Deale rIDColumn;
DataColumn cdc = dtLocations.Dea lerIDColumn;

DataRelation dr = new DataRelation("D ealerToLocation s", pdc, cdc);
ds.Relations.Ad d(dr);

bmDealers = this.BindingCon text[ds, "Dealers"];

drDealer = dtDealers.FindB yDealerID(nDeal erID);
bmDealers.Posit ion = dtDealers.Rows. IndexOf(drDeale r);

txtDealerID.Dat aBindings.Add(n ew Binding("Text", ds,
"Dealers.Dealer ID"));
txtDealerName.D ataBindings.Add (new Binding("Text", ds,
"Dealers.Dealer Name"));

cboBillToLocati on.DataSource = ds;
cboBillToLocati on.DisplayMembe r =
"Dealers.Dealer ToLocations.Loc ationDescriptio n";
cboBillToLocati on.ValueMember =
"Dealers.Dealer ToLocations.Loc ationID";
cboBillToLocati on.DataBindings .Add(new Binding("Select edValue",
ds, "Dealers.BillTo Location"));

Nov 19 '06 #1
3 4205
Can anyone help here? It's pretty important and I can't find any examples
anywhere.

Thanks,

Bill

"Bill" wrote:
I have what I think should be a simple question regarding a bound combo box.
My first table is Dealers:
DealerID - primary key
DealerName
BillToLocation

My second table is Locations:
LocationID - primary key
LocationDescrip tion
DealerID - DealerID of the dealer this location belongs to

I want a bound combo box that when on a dealer record it displays the
LocationDescrip tion for the dealer record's BillToLocation. But I want the
user to be able to change the BillToLocation to one of the dealers locations
in the Locations table.

At this point I have a combo box that shows only that Dealer's locations in
the drop down list, will update the BillToLocation when it's selected and
saved, but unfortunately it doesn't display correctly as I navigate through
the records using bmDealers.Posit ion++ or bmDealers.Posit ion--;
Interestingly enough, if I load a particular dealer record, it displays the
correct LocationDescrip tion, but if navigate away and then back, it gets out
of sync.

Could someone give me some guidance as to what I'm doing wrong? Thank you.

Here is the binding code:
dsCoinTableAdap ters.DealersTab leAdapter daDealers = new
dsCoinTableAdap ters.DealersTab leAdapter();
dtDealers = ds.Dealers;
daDealers.Fill( dtDealers);

dsCoinTableAdap ters.LocationsT ableAdapter daLocations = new
dsCoinTableAdap ters.LocationsT ableAdapter();
dtLocations = ds.Locations;
daLocations.Fil l(dtLocations);

DataColumn pdc = dtDealers.Deale rIDColumn;
DataColumn cdc = dtLocations.Dea lerIDColumn;

DataRelation dr = new DataRelation("D ealerToLocation s", pdc, cdc);
ds.Relations.Ad d(dr);

bmDealers = this.BindingCon text[ds, "Dealers"];

drDealer = dtDealers.FindB yDealerID(nDeal erID);
bmDealers.Posit ion = dtDealers.Rows. IndexOf(drDeale r);

txtDealerID.Dat aBindings.Add(n ew Binding("Text", ds,
"Dealers.Dealer ID"));
txtDealerName.D ataBindings.Add (new Binding("Text", ds,
"Dealers.Dealer Name"));

cboBillToLocati on.DataSource = ds;
cboBillToLocati on.DisplayMembe r =
"Dealers.Dealer ToLocations.Loc ationDescriptio n";
cboBillToLocati on.ValueMember =
"Dealers.Dealer ToLocations.Loc ationID";
cboBillToLocati on.DataBindings .Add(new Binding("Select edValue",
ds, "Dealers.BillTo Location"));
Nov 20 '06 #2
Hi,

"Bill" <Bi**@discussio ns.microsoft.co mwrote in message
news:97******** *************** ***********@mic rosoft.com...
>I have what I think should be a simple question regarding a bound combo
box.
My first table is Dealers:
DealerID - primary key
DealerName
BillToLocation

My second table is Locations:
LocationID - primary key
LocationDescrip tion
DealerID - DealerID of the dealer this location belongs to

I want a bound combo box that when on a dealer record it displays the
LocationDescrip tion for the dealer record's BillToLocation. But I want
the
user to be able to change the BillToLocation to one of the dealers
locations
in the Locations table.

At this point I have a combo box that shows only that Dealer's locations
in
the drop down list, will update the BillToLocation when it's selected and
saved, but unfortunately it doesn't display correctly as I navigate
through
the records using bmDealers.Posit ion++ or bmDealers.Posit ion--;
Interestingly enough, if I load a particular dealer record, it displays
the
correct LocationDescrip tion, but if navigate away and then back, it gets
out
of sync.

Could someone give me some guidance as to what I'm doing wrong?
Problem :

The CurrencyManager (Dealers) maintains a position, when this position
changes then:
* the CurrencyManager will force all bindings to read value from datasource
to control,
* it will then fire CurrentItemChan ged (among others), this event is handled
by:
- the RelatedCurrency Manager (Locations) and it will update the child
list.

So, SelectedValue is set *before* the child list is updated and updating a
child list causes a ListChanged(Res et) which makes the ComboBox always
select the first item. We need to get an event after the child list is
updated, then we can set SelectedValue.

This is possible by adding an eventhandler to
CurrencyManager .CurrentItemCha nged after the RelatedCurrency Manager is
created (after binding to the child list).

See updated code:

CurrencyManager cmDealers;

private void FormLoad(...)
{
dsCoinTableAdap ters.DealersTab leAdapter daDealers = new
dsCoinTableAdap ters.DealersTab leAdapter();
dtDealers = ds.Dealers;
daDealers.Fill( dtDealers);

dsCoinTableAdap ters.LocationsT ableAdapter daLocations = new
dsCoinTableAdap ters.LocationsT ableAdapter();
dtLocations = ds.Locations;
daLocations.Fil l(dtLocations);

DataColumn pdc = dtDealers.Deale rIDColumn;
DataColumn cdc = dtLocations.Dea lerIDColumn;
ds.Relations.Ad d("DealerToLoca tions", pdc, cdc);

// bm is really a CurrencyManager
cmDealers = (CurrencyManage r) this.BindingCon text[ds, "Dealers"];

cmDealers.Posit ion =
((IBindingList) cmDealers.List) .Find(cmDealers .GetItemPropert ies().Find("Dea lerID",
false), nDealerID);

// binding parent list
txtDealerID.Dat aBindings.Add(" Text", ds, "Dealers.Dealer ID");
txtDealerName.D ataBindings.Add ("Text", ds, "Dealers.Dealer Name"));

// binding child list
cboBillToLocati on.DataSource = ds;
cboBillToLocati on.DisplayMembe r =
"Dealers.Dealer ToLocations.Loc ationDescriptio n";
cboBillToLocati on.ValueMember = "Dealers.Dealer ToLocations.Loc ationID";

cboBillToLocati on.DataBindings .Add("SelectedV alue", ds,
"Dealers.BillTo Location");

// after binding the child list
cmDealers.Curre ntItemChanged+= new EventHandler(
cmDealers_Curre ntItemChanged );
}

private void cmDealers_Curre ntItemChanged(o bject sender, EventArgs e)
{
// because we subscribed to this event *after binding to the child list*,
this
// will be invoked after the child list is updated, read the value from
source
cboBillToLocati on.DataBindings["SelectedVa lue"].ReadValue();
}
HTH,
Greetings
Nov 21 '06 #3
Bart,

Thank you so much. This will be a big help. I had conceded to coding a
klunky workaround, so this will be much better.

Thanks again,

Bill

"Bart Mermuys" wrote:
Hi,

"Bill" <Bi**@discussio ns.microsoft.co mwrote in message
news:97******** *************** ***********@mic rosoft.com...
I have what I think should be a simple question regarding a bound combo
box.
My first table is Dealers:
DealerID - primary key
DealerName
BillToLocation

My second table is Locations:
LocationID - primary key
LocationDescrip tion
DealerID - DealerID of the dealer this location belongs to

I want a bound combo box that when on a dealer record it displays the
LocationDescrip tion for the dealer record's BillToLocation. But I want
the
user to be able to change the BillToLocation to one of the dealers
locations
in the Locations table.

At this point I have a combo box that shows only that Dealer's locations
in
the drop down list, will update the BillToLocation when it's selected and
saved, but unfortunately it doesn't display correctly as I navigate
through
the records using bmDealers.Posit ion++ or bmDealers.Posit ion--;
Interestingly enough, if I load a particular dealer record, it displays
the
correct LocationDescrip tion, but if navigate away and then back, it gets
out
of sync.

Could someone give me some guidance as to what I'm doing wrong?

Problem :

The CurrencyManager (Dealers) maintains a position, when this position
changes then:
* the CurrencyManager will force all bindings to read value from datasource
to control,
* it will then fire CurrentItemChan ged (among others), this event is handled
by:
- the RelatedCurrency Manager (Locations) and it will update the child
list.

So, SelectedValue is set *before* the child list is updated and updating a
child list causes a ListChanged(Res et) which makes the ComboBox always
select the first item. We need to get an event after the child list is
updated, then we can set SelectedValue.

This is possible by adding an eventhandler to
CurrencyManager .CurrentItemCha nged after the RelatedCurrency Manager is
created (after binding to the child list).

See updated code:

CurrencyManager cmDealers;

private void FormLoad(...)
{
dsCoinTableAdap ters.DealersTab leAdapter daDealers = new
dsCoinTableAdap ters.DealersTab leAdapter();
dtDealers = ds.Dealers;
daDealers.Fill( dtDealers);

dsCoinTableAdap ters.LocationsT ableAdapter daLocations = new
dsCoinTableAdap ters.LocationsT ableAdapter();
dtLocations = ds.Locations;
daLocations.Fil l(dtLocations);

DataColumn pdc = dtDealers.Deale rIDColumn;
DataColumn cdc = dtLocations.Dea lerIDColumn;
ds.Relations.Ad d("DealerToLoca tions", pdc, cdc);

// bm is really a CurrencyManager
cmDealers = (CurrencyManage r) this.BindingCon text[ds, "Dealers"];

cmDealers.Posit ion =
((IBindingList) cmDealers.List) .Find(cmDealers .GetItemPropert ies().Find("Dea lerID",
false), nDealerID);

// binding parent list
txtDealerID.Dat aBindings.Add(" Text", ds, "Dealers.Dealer ID");
txtDealerName.D ataBindings.Add ("Text", ds, "Dealers.Dealer Name"));

// binding child list
cboBillToLocati on.DataSource = ds;
cboBillToLocati on.DisplayMembe r =
"Dealers.Dealer ToLocations.Loc ationDescriptio n";
cboBillToLocati on.ValueMember = "Dealers.Dealer ToLocations.Loc ationID";

cboBillToLocati on.DataBindings .Add("SelectedV alue", ds,
"Dealers.BillTo Location");

// after binding the child list
cmDealers.Curre ntItemChanged+= new EventHandler(
cmDealers_Curre ntItemChanged );
}

private void cmDealers_Curre ntItemChanged(o bject sender, EventArgs e)
{
// because we subscribed to this event *after binding to the child list*,
this
// will be invoked after the child list is updated, read the value from
source
cboBillToLocati on.DataBindings["SelectedVa lue"].ReadValue();
}
HTH,
Greetings
Nov 21 '06 #4

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

Similar topics

2
5832
by: Daniel Tan | last post by:
Hi, how can i obtain the value of combobox multiple bound column data ? Eg, if i select combo box, it has more than one field, name and age and id listed. Pls advise, thanks. Regards, Daniel
19
4120
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
2
7769
by: Ed via AccessMonster.com | last post by:
Hi all, What I am trying to do is get the value of the second column of a bound combo box in vba. example: Combo box: column 1-ID column 2-SIGN_CODE 1 R-1.gif 2 R-2.gif
3
16664
by: Cindi Simonson | last post by:
Hi, I have a form with a combo box containing 4 columns of data. The form also contains 3 print buttons where the goal is to open 3 different reports according to the value in one of the columns of the combo box. Since the bound column property determines which value to look at, how do I change the bound column's value in an onClick event?
4
4624
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have distilled the problem down to a simple form drawing data from the Northwind database for a representative...
4
2678
by: Evan | last post by:
I have a data bound combo box. The combo box displays several items (status code descriptions). After the combo box is bound, I want to set the combo box so that the "Draft" status is displayed by default. Since the data originally comes from a database I don't know which position in the combo box it will be and I don't want to hardcode the status_code field (I want to select the combo box item based upon status_desc). ...
1
4875
by: Bill | last post by:
Problem: Combo box data disappears from view when a requery is done See "Background" below for details on tables, forms & controls On a form, I want to use the setting of bound combo box C1 to limit what is displayed in bound combo box C2. When I display Tbl-A records on a continuous form, and navigate away from record 1 to record 2, the previously entered data displayed in C2 for record 1 disappears from
9
32631
by: Vmusic | last post by:
Hi, I'm using MS Access 2002. I have a form with a combo box built from a query that returns one column, and that one column is the bound column. How do you use VBA to programmatically change which row in the combo box is selected?? I looked at the forum and the answers aren't very clear. Of course the MS Access help file is worthless.
1
2306
by: _JB_ | last post by:
Hi, I'm having problems changing the selected entry in a combo box when it's Row Source Type is Table/Query. I can do it easily when it's of Value List type by setting the Value property. However I can't seem to find a way to set the combo box when its data bound. Can anyone help me out? Cheers JB
0
9872
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
9715
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,...
1
10672
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
10314
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
9453
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...
0
7038
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
5885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4499
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
4089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.