Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Binding to a DataSet and related rows

Closed Thread
 
Thread Tools Display Modes
Old 10-11-2006   #1 (permalink)
jmagaram
Guest


 

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>
Old 10-11-2006   #2 (permalink)
jmagaram
Guest


 

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>

Old 10-11-2006   #3 (permalink)
Douglas Stockwell
Guest


 

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>


Old 10-12-2006   #4 (permalink)
Bart Mermuys
Guest


 

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>



Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternate rows colors Jason1008 PowerShell 2 06-10-2008 04:18 AM
Binding inside binding question Yoavo Avalon 0 12-03-2007 08:24 AM
Binding Question (Binding in General) Jason Avalon 2 05-09-2007 04:41 AM
Add-on or tweak for multiple tab rows in IE7... michail iakovou yos Vista General 3 01-06-2007 07:58 PM
Binding a TreeView to a large dataset. Tom Avalon 1 04-20-2006 01:03 PM








Vistax64.com 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 2005-2008

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 47 48 49 50