views:

34

answers:

2

I've created a dataset that contains 2 tables: Users (userID, UserName, other user details) Emails (Id, UserId, UserEmail)

I populate the dataset using 2 DataAdapters (one for each table)

I have a listbox, a few textboxes and a grid. listbox gets all the users, the few textboxs displays the user details when picked in the list box (this is easy b/c they are both bound to the same table).

the grid should display the selected user's email addresses.

How do I do it using binding ? is it possible or should I catch the selection change event and filter the grid "manually" (currently the grid displays all the emails in the tables).

A: 

If you have a collection that contains all the emails, then you could try looking at making the ItemsSource of your grid an object that implements the ICollectionView interface - this allows you to filter, sort and group your collection...

You can get an object that implements this interface by calling

var view = CollectionViewSource.GetDefaultView(myList);
IanR
A: 

You can have a property called SelectedUser and bind it to the SelectedItem of ListBox. In the setter of the property you can filter the email list that is bound to grid.

But in the long run, you can create models out of your tables using some ORM tools or Linq-to-sql available in VS which will create models and their relationship. Hence when you will have something like this

Class User
{
    UserId, UserName, List<Email> that user has
}

You can create a List<User> and a SelectedUser property which would be bound to the UI elements.

The grid would be bound to SelectedUser.Emails Hence everything is bound and the flow would work fine.

Veer