dotnet windows forms databinding:
What is the best method to display columns in a parent table and not
using comboboxes? Example:
You have an Order entry form and want to display additional columns from
the customer table, let say customer name and adress.
If you use a combobox and bind the selected value to the order customer
id and set the datasource to customer binding source (and corresponding
displaymember, valuemember) then everything works by the book.
But if we don't want to use a combobox then I haven't found any samples
how to do this. With some trial and error I have found out that I can
use the CurrentChanged event in the Order binding source, get the value
of the Order.Customerid and set the position in the customer
bindingsource, for example liek this:
(in CurrentChanged of OrderBindingSource
Dim orderRow as OrderDataSet.OrderRow
orderRow=OrderBindingSource.Current.Row
If orderRow.CustomerId IsNot Nothing Then
Dim index = CustomerBindingSource.Find("Customerid",
orderRow.CustomerId)
if Index > -1 Then CustomerBindingSource.Position= index
End If
My textboxes for customer data is of course bound to the customer
binding source. This works fine.
Is this the right method to do this or is there any better way to do it?
Only examples I have found is to set filter of the parent bindingsource
which also works but I like my approach better.
Now to the second part, I also want to select customer by entering a
customer id (and still not using a combobox, forget for now that it
might be a better method. I am trying to learn how to do things in
..NET).
When I enter a customer id I want to find and display customer name and
other data from the customer table. What I have done is to use the find
method of CustomerBindingSource in the validating event of the
customerid textbox to find the correct customerrow. Any better ways to
do this?