Home All Groups Group Topic Archive Search About

Child DataView is not updating automatically

Author
20 Oct 2006 8:40 PM
jmagaram
I am trying to display list of people and for each person a list of their
corresponding phone numbers. I am doing this with databinding in outline form
with WPF with all nodes expanded. If the user inserts a new Person and types
in a bunch of their phone numbers it seems to work OK. But if the user
changes the name of the person then the list of their associated phone
numbers completely disappears. I don’t think this is a UI problem but rather
a problem with child views.

My dataset has two tables, shown below. There is a cascading foreign key
DataRelation called FK_Person_Phones. The primary key of each table spans all
of its columns.

Person (FullName)
PersonWithPhone (FullName, Phone)

Here is a code excerpt to show what is going on:

1.    DataSet data = new DataSet();
2.    data.ReadXml("SampleData.xml");
3.    DataView peopleView = new DataView(data.Tables["Person"]);
4.    DataView phonesOfFirstPersonView =
peopleView[0].CreateChildView("FK_Person_Phones");
5.    // phonesOfFirstPersonView.Count == 2
6.    data.Tables["Person"].Rows[0]["FullName"] = "Updated Name";
7.    // phonesOfFirstPersonView.Count == 0

Why does the child view show no rows after line 6, especially since there is
a cascading foreign key relation? I assumed that the child view (being a
RelatedView after all) would always look for children of its parent row even
after the parent row’s primary key changes.

One workaround for this problem is to prevent the user from ever changing
the primary key. In the user interface this means I must make creating a
Person a modal process – display a dialog to collect the primary key value.
After the dialog is dismissed I would allow the user to type in phone numbers
for that person but the person’s name would be read-only. Another option is
to always use a meaningless surrogate key, like PersonID. Neither of these
options are very appealing for my actual scenario - the above scenario is a
simplification. A third option is for me to subclass DataView to monitor
changes in the parent row’s primary key value. I am very surprised that the
..NET framework doesn’t handle this type of hierarchical data binding
automatically. Am I doing something wrong or missing the point?

AddThis Social Bookmark Button