H
hawbsys
Dear all. I'm wondering why it's so hard to bind a lookup value from
a
related table into a textbox on my form.
Say I've got two tables, product and productcategory. I'm paging
through product information using the bindingnavigator, one product
per page. Everything on the form is bound to fields in the product
table. Description, price, notes productcategoryid. Nice and simple
Ado.net bound form.
But instead of the ID value for product category I'd like to see the
productcategory.description. A lookup value. The relationship between
the two tables is defined in the dataset.
All the samples for this kind of thing are parent-child datagrids and
comboboxes. I just want a simple textbox lookup. I don't want
comboboxes. I don't need two way binding, just a readonly lookup.
I can get what I want by a) using a combo, b) using lots of code and
filters on the bindingsource but there must be an easier way. After
all, if it's easy with a combo box (and it is, just slot in the
selectedvalue, displaymember, valuemember), then it's got to be easy-
peasy using a textbox or a label.
Someone else suggested c) using a join in the original select but that
breaks
breaks a key element of binding. If the description for
productcategory is changed in another form
(sharing the same dataset) the original form knows nothing about the
change and the "old" name is still shown. The beauty of ADO.NET
databinding, is that you can expect your changes to propagate to all
other parts of your application without extra code. Compare with a
combobox (an updated productcategory description shows seamlessly in
the original form if you change productcategory description in
another
form so long as they share the same dataset)
Do I need a DataRelation? I've had a look at them but they don't seem
to solve my problem.
hawbsl
a
related table into a textbox on my form.
Say I've got two tables, product and productcategory. I'm paging
through product information using the bindingnavigator, one product
per page. Everything on the form is bound to fields in the product
table. Description, price, notes productcategoryid. Nice and simple
Ado.net bound form.
But instead of the ID value for product category I'd like to see the
productcategory.description. A lookup value. The relationship between
the two tables is defined in the dataset.
All the samples for this kind of thing are parent-child datagrids and
comboboxes. I just want a simple textbox lookup. I don't want
comboboxes. I don't need two way binding, just a readonly lookup.
I can get what I want by a) using a combo, b) using lots of code and
filters on the bindingsource but there must be an easier way. After
all, if it's easy with a combo box (and it is, just slot in the
selectedvalue, displaymember, valuemember), then it's got to be easy-
peasy using a textbox or a label.
Someone else suggested c) using a join in the original select but that
breaks
breaks a key element of binding. If the description for
productcategory is changed in another form
(sharing the same dataset) the original form knows nothing about the
change and the "old" name is still shown. The beauty of ADO.NET
databinding, is that you can expect your changes to propagate to all
other parts of your application without extra code. Compare with a
combobox (an updated productcategory description shows seamlessly in
the original form if you change productcategory description in
another
form so long as they share the same dataset)
Do I need a DataRelation? I've had a look at them but they don't seem
to solve my problem.
hawbsl