D
Dan
I'm relatively new to forms databinding, anyway I have experimented a bit
and I have a couple of questions:
1) often, the databinding mechanism seems not to realize that changes have
been made to the bound control value(s). For instance, if I bind a textbox
or a numeric up-down control to a data source (a datatable row's field), the
display is always correct, but if I change some letters in the textbox or a
value in the up-down control, WITHOUT moving around to other controls in the
form for a while, the call to EndCurrentEdit *does not reflect* the new
value in the controls. I call EndCurrentEdit like:
BindingContext[myDataSet, "tableName"].EndCurrentEdit();
for each table in my dataset whose field(s) are bound to any control in the
form. The correct value is reflected only when I move the focus to other
controls in the form, if I just change the control contents and then click
on my UPDATE button, the underlying datarow state remains UNCHANGED. Is this
my fault, or it's just a buggy behaviour of databinding?
2) what's the correct way for binding to a combobox? Let's say I have a form
which displays some 'lookup' data in a combo: these data are bound to a
parent table (e.g. Countries), and the selected item primary key is linked
to a corresponding foreign key in a child table (e.g. Customer): the
database looks like:
TCustomer: customerID, countryID (the foreign key), ...
TCountry: countryID (the primary key), country
The countries combo will be bound to my (typed) dataset's table TCountry as
follows:
myCombo.DataBindings.Add(new Binding("SelectedValue", myDataSet,
"TCountry.countryID"));
myCombo.DataSource = myDataSet.TCountry;
myCombo.DisplayMember = "country";
myCombo.ValueMember = "countryID";
Now, when loading customer's data into the form, I'll have to "manually"
select the correct country in the lookup combo:
MyDataSet.TCountryRow row =
myDataSet.TCountry.FindBycountryID(row.countryID);
myCombo.SelectedIndex = myCombo.FindStringExact(row.country);
And when updating the database, before calling EndCurrentEdit() and updating
via the data adapter I'll have to do the inverse:
theCustomerRow.countryID = (int)_myCombo.SelectedValue;
Is this OK, or is there a better way for doing it?
and I have a couple of questions:
1) often, the databinding mechanism seems not to realize that changes have
been made to the bound control value(s). For instance, if I bind a textbox
or a numeric up-down control to a data source (a datatable row's field), the
display is always correct, but if I change some letters in the textbox or a
value in the up-down control, WITHOUT moving around to other controls in the
form for a while, the call to EndCurrentEdit *does not reflect* the new
value in the controls. I call EndCurrentEdit like:
BindingContext[myDataSet, "tableName"].EndCurrentEdit();
for each table in my dataset whose field(s) are bound to any control in the
form. The correct value is reflected only when I move the focus to other
controls in the form, if I just change the control contents and then click
on my UPDATE button, the underlying datarow state remains UNCHANGED. Is this
my fault, or it's just a buggy behaviour of databinding?
2) what's the correct way for binding to a combobox? Let's say I have a form
which displays some 'lookup' data in a combo: these data are bound to a
parent table (e.g. Countries), and the selected item primary key is linked
to a corresponding foreign key in a child table (e.g. Customer): the
database looks like:
TCustomer: customerID, countryID (the foreign key), ...
TCountry: countryID (the primary key), country
The countries combo will be bound to my (typed) dataset's table TCountry as
follows:
myCombo.DataBindings.Add(new Binding("SelectedValue", myDataSet,
"TCountry.countryID"));
myCombo.DataSource = myDataSet.TCountry;
myCombo.DisplayMember = "country";
myCombo.ValueMember = "countryID";
Now, when loading customer's data into the form, I'll have to "manually"
select the correct country in the lookup combo:
MyDataSet.TCountryRow row =
myDataSet.TCountry.FindBycountryID(row.countryID);
myCombo.SelectedIndex = myCombo.FindStringExact(row.country);
And when updating the database, before calling EndCurrentEdit() and updating
via the data adapter I'll have to do the inverse:
theCustomerRow.countryID = (int)_myCombo.SelectedValue;
Is this OK, or is there a better way for doing it?