Fundamental question about bound controls

G

Guest

I have a WinForm with controls bound to a typed recordset that was generated
by the Dataset Designer. There are several ComboBox controls with their
DataSource bound to different lookup tables. Everything is working fine,
except when I need to handle a null default value in the data record coming
from the database. I want the combo whose SelectedValue is bound to that
field to display the "default" entry in the combo in this case. I tried the
following code:

if (rowService.IsDefaultCourierNull()) rowService.DefaultCourier = 0;

If the branch is taken and the DefaultCourier value is changed, *all* the
bound controls go blank. I've tried placing this statement alternatively
before or after doing the Refresh of the CurrentyManager. No difference.
The following statement, placed *after* the refresh, *does* work:

if (rowService.IsDefaultCourierNull()) cboCourier.SelectedIndex = 0;

I'm new to WinForms, and it seems like there's something fundamental about
binding that I don't understand. What is the correct way to alter values in
the source DataRow when those values are bound to controls? Is changing the
value in the bound control the correct approach?
 
P

Pete Davis

What is the "rowService" object? What does the "IsDefaultCourierNull()"
method do? It's not part of the framework that I can find. In fact, a google
search on IsDefaultCourierNull returned nothing.

When you provide sample code, please provide some context with which it
makes sense to us.

Pete
 
G

Guest

Sorry. rowService is of a typed DataRow class generated by the DataSet
Designer. The Designer generates properties for accessing the column values
in the row. rowService.DefaultCourier is the same as
rowService["DefaultCourier"] except the property is typed as Int32 by the
Designer. Likewise, the Designer generates methods for testing nullable
columns: rowService.IsDefaultCourierNull() is the same as
(rowService["DefaultCourier"] == null).
 
P

Pete Davis

Well, you're going to have to change the way the ComboBox represents the
data without actually altering the data. If you alter the data, then that
alteration will be propagated across all controls bound to the same
datasource from the same BindingContext.

What you'll probably have to do is not automatically bind the data and
handle movement between the ComboBox and DataSet by hand.

Pete

kaborka said:
Sorry. rowService is of a typed DataRow class generated by the DataSet
Designer. The Designer generates properties for accessing the column values
in the row. rowService.DefaultCourier is the same as
rowService["DefaultCourier"] except the property is typed as Int32 by the
Designer. Likewise, the Designer generates methods for testing nullable
columns: rowService.IsDefaultCourierNull() is the same as
(rowService["DefaultCourier"] == null).

Pete Davis said:
What is the "rowService" object? What does the "IsDefaultCourierNull()"
method do? It's not part of the framework that I can find. In fact, a google
search on IsDefaultCourierNull returned nothing.

When you provide sample code, please provide some context with which it
makes sense to us.

Pete

tried
the values
in changing
the
 
G

Guest

That seems pretty severe. Is there no way to alter the data in a DataSet via
code, and have the altered values appear in the controls bound to the DataSet?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top