![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Alternate rows colors | PowerShell | |||