all groups > dotnet windows forms databinding > may 2007 >
You're in the

dotnet windows forms databinding

group:

Displaying data from parent


Displaying data from parent Magnus Bergh
5/18/2007 4:59:23 PM
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?
Re: Displaying data from parent Martin P
5/24/2007 1:10:24 AM
[quoted text, click to view]

Hi

I suppose it depends on how you're getting your data etc. For
example, it looks like, in your sample, you're pre-loading all of the
'parents' before you begin - customers in this case, but what if you
have 10,000+ customers? Are you really going to load all of the data
upfront?

Personally, I'd be tempted to do one of the following:

1. Load the parent/customer info individually when you need it -
whether you cache this data or not is up to you and your requirements

2. Create a view on your database that brings back all of the columns/
fields that you need and just use that instead.

As for your customer searching, again, it depends on whether you pre-
load all of the parent data first, in which case your method sounds
fine (I'd only use the Filter method if there was a possiblility of
returning > 1 customer - ie. if you were searching by address etc
rather than by customerID). Personally, I wouldn't load up all of my
customers in one hit as it's unlikely that the user will need ALL of
the customer data in one session.

Hope that helps
Martin
Re: Displaying data from parent RB
6/9/2007 10:11:18 PM
Martin:

I have a similar project and this seems like good advice. How does one
create a "View"? I am not familiar with transact SQL but, can a view be
stored and referenced like a table adpapter?

I posted the subject "Load Combo Box From Joined Tables" on 6/9/07 in this
same group. If you could answer in that perspective, I would really
appreciate it. I'll check this post and that.

RB
--
remove underscore to send me mail, no spam
[quoted text, click to view]

Re: Displaying data from parent Martin P
6/27/2007 12:00:00 AM
[quoted text, click to view]

Hi

Sorry I haven't answered sooner, I haven't visited the ng here for a
while now.

As for creating a view, you can do this either using Transact SQL or
you can do it using whatever management tool you're using for SQL
Server (Management Studio for example). It is created on the database
and in many ways acts like a table (i.e. you can query it as you would
a table etc) but there are limitations - the main one being that views
(typically) are not updateable so you would use them mainly for
creating read-only lists etc - hence the name "View". It is possible
to create updateable views but they are quite restricted so your
mileage from doing so may vary. Your best bet would be to look up
Views in SQL Books on Line (your SQL Server help docs).

I'll take a quick look at your other post now but am pushed for time
so may not be able to post an answer - I'll do what I can

Cheers
Martin
AddThis Social Bookmark Button