Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Binding to a DataSet and related rows

 
 
Old 10-11-2006   #1 (permalink)
jmagaram


 
 

Binding to a DataSet and related rows

I have a DataSet filled with two tables:

Person [PersonID,First,Last]
PhoneNumber [PersonID,PhoneNumber,PhoneType]

I want to display a tree of each person and their list of phone numbers. The
top level is easy - I bind to a DataView on the Person table. But I can't
figure out how to also show the associated phone numbers (as a DataView so it
gets updated automatically). One idea I had was to create a Method on the
DataSet something like this:

DataView GetPhoneNumbers(DataRow person)

I don't know how to refer to this method in the ItemsSource in the XAML.
Binding to properties seems straightforward, but not to methods. The
templates look something like this:

<DataTemplate x:Key="PhoneRowTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=PhoneType}"/>
<TextBlock Text="{Binding Path=PhoneNumber}"/>
</StackPanel>
</DataTemplate>

<DataTemplate x:Key="PersonRowTemplate">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Path=First}"/>
<TextBlock Text="{Binding Path=Last}"/>
<ListBox ItemsSource="?????" ItemTemplate="{StaticResource
PhoneRowTemplate}"></ListBox>
</StackPanel>
</DataTemplate>

My System SpecsSystem Spec
Old 10-11-2006   #2 (permalink)
jmagaram


 
 

RE: Binding to a DataSet and related rows

I implemented a major hack to solve this. For each row in the parent table, I
created a column of type DataView called RelatedPhoneNumbers and filled it
with a custom built DataView. Each time a row is added to the parent table,
the TableNewRow event fills in this special column automatically. Then I just
set the ItemsSource property to "RelatedPhoneNumbers". There must be a better
way.

Ideas anyone?

"jmagaram" wrote:

> I have a DataSet filled with two tables:
>
> Person [PersonID,First,Last]
> PhoneNumber [PersonID,PhoneNumber,PhoneType]
>
> I want to display a tree of each person and their list of phone numbers. The
> top level is easy - I bind to a DataView on the Person table. But I can't
> figure out how to also show the associated phone numbers (as a DataView so it
> gets updated automatically). One idea I had was to create a Method on the
> DataSet something like this:
>
> DataView GetPhoneNumbers(DataRow person)
>
> I don't know how to refer to this method in the ItemsSource in the XAML.
> Binding to properties seems straightforward, but not to methods. The
> templates look something like this:
>
> <DataTemplate x:Key="PhoneRowTemplate">
> <StackPanel Orientation="Horizontal">
> <TextBlock Text="{Binding Path=PhoneType}"/>
> <TextBlock Text="{Binding Path=PhoneNumber}"/>
> </StackPanel>
> </DataTemplate>
>
> <DataTemplate x:Key="PersonRowTemplate">
> <StackPanel Orientation="Vertical">
> <TextBlock Text="{Binding Path=First}"/>
> <TextBlock Text="{Binding Path=Last}"/>
> <ListBox ItemsSource="?????" ItemTemplate="{StaticResource
> PhoneRowTemplate}"></ListBox>
> </StackPanel>
> </DataTemplate>

My System SpecsSystem Spec
Old 10-11-2006   #3 (permalink)
Douglas Stockwell


 
 

Re: Binding to a DataSet and related rows

You could use a Converter (see IValueConverter). This is similar to calling
your GetPhoneNumbers method.

<ListBox ItemsSource="{Binding Converter={...}}"
ItemTemplate="{StaticResource ...

Assuming you can crawl back up the data structure to get the DataSet from a
Person row.

- Doug

"jmagaram" <jmagaram@discussions.microsoft.com> wrote in message
news:CB22A3FE-34BD-4991-A195-46675765A8AF@microsoft.com...
>I have a DataSet filled with two tables:
>
> Person [PersonID,First,Last]
> PhoneNumber [PersonID,PhoneNumber,PhoneType]
>
> I want to display a tree of each person and their list of phone numbers.
> The
> top level is easy - I bind to a DataView on the Person table. But I can't
> figure out how to also show the associated phone numbers (as a DataView so
> it
> gets updated automatically). One idea I had was to create a Method on the
> DataSet something like this:
>
> DataView GetPhoneNumbers(DataRow person)
>
> I don't know how to refer to this method in the ItemsSource in the XAML.
> Binding to properties seems straightforward, but not to methods. The
> templates look something like this:
>
> <DataTemplate x:Key="PhoneRowTemplate">
> <StackPanel Orientation="Horizontal">
> <TextBlock Text="{Binding Path=PhoneType}"/>
> <TextBlock Text="{Binding Path=PhoneNumber}"/>
> </StackPanel>
> </DataTemplate>
>
> <DataTemplate x:Key="PersonRowTemplate">
> <StackPanel Orientation="Vertical">
> <TextBlock Text="{Binding Path=First}"/>
> <TextBlock Text="{Binding Path=Last}"/>
> <ListBox ItemsSource="?????" ItemTemplate="{StaticResource
> PhoneRowTemplate}"></ListBox>
> </StackPanel>
> </DataTemplate>


My System SpecsSystem Spec
Old 10-12-2006   #4 (permalink)
Bart Mermuys


 
 

Re: Binding to a DataSet and related rows

Hi,

"jmagaram" <jmagaram@discussions.microsoft.com> wrote in message
news:29DEC174-5E49-4876-B333-9E848354452B@microsoft.com...
>I implemented a major hack to solve this. For each row in the parent table,
>I
> created a column of type DataView called RelatedPhoneNumbers and filled it
> with a custom built DataView. Each time a row is added to the parent
> table,
> the TableNewRow event fills in this special column automatically. Then I
> just
> set the ItemsSource property to "RelatedPhoneNumbers". There must be a
> better
> way.
>


If you add a "Person-PhoneNumber" DataRelation to the DataSet, then the
DataView of the Person table will already have an extra column (with the
same name as the relation) which returns a child DataView of the PhoneNumber
table.

HTH,
Greetings


> Ideas anyone?
>
> "jmagaram" wrote:
>
>> I have a DataSet filled with two tables:
>>
>> Person [PersonID,First,Last]
>> PhoneNumber [PersonID,PhoneNumber,PhoneType]
>>
>> I want to display a tree of each person and their list of phone numbers.
>> The
>> top level is easy - I bind to a DataView on the Person table. But I can't
>> figure out how to also show the associated phone numbers (as a DataView
>> so it
>> gets updated automatically). One idea I had was to create a Method on the
>> DataSet something like this:
>>
>> DataView GetPhoneNumbers(DataRow person)
>>
>> I don't know how to refer to this method in the ItemsSource in the XAML.
>> Binding to properties seems straightforward, but not to methods. The
>> templates look something like this:
>>
>> <DataTemplate x:Key="PhoneRowTemplate">
>> <StackPanel Orientation="Horizontal">
>> <TextBlock Text="{Binding Path=PhoneType}"/>
>> <TextBlock Text="{Binding Path=PhoneNumber}"/>
>> </StackPanel>
>> </DataTemplate>
>>
>> <DataTemplate x:Key="PersonRowTemplate">
>> <StackPanel Orientation="Vertical">
>> <TextBlock Text="{Binding Path=First}"/>
>> <TextBlock Text="{Binding Path=Last}"/>
>> <ListBox ItemsSource="?????" ItemTemplate="{StaticResource
>> PhoneRowTemplate}"></ListBox>
>> </StackPanel>
>> </DataTemplate>



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Alternate rows colors PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46