Master detail..
Hi,
I am new to this so please go slow with me.
I am trying to create master-detail relationship using two list boxes. I am using "Three Level Master Detail ADO" sample code as reference. I cant figure out what am i doing wrong. Please help. I am copy pasting code here. (By the way i have renamed fields CustomerID to code & CompanyName to name in customer table)
How I can achieve show orders only for selected customer in first listbox?
Thank you
Window2.xaml
<Window x:Class="ATTest.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="Test1" Height="277" Width="356" WindowStartupLocation="CenterScreen"><Window.Resources>
<Style TargetType="{x:Type ListBox}">
<Setter Property="Height" Value="60"/>
<Setter Property="Width" Value="160"/>
</Style>
<Style TargetType="{x:Type Label}">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="Red" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</Window.Resources>
<Border Margin="30" BorderBrush="Blue" BorderThickness="2" Padding="10">
<StackPanel>
<ListBox Width="200" Margin="10" ItemsSource="{Binding Path=Customers}" Name="lstCustomer" IsSynchronizedWithCurrentItem="true" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label VerticalAlignment="Center">Code:</Label>
<TextBlock Text="{Binding Path=code}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Foreground="Green" VerticalAlignment="Center">Name:</Label>
<TextBlock Text="{Binding Path=name}" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Name="sp">
<StackPanel Orientation="Horizontal">
<StackPanel Margin="5">
<Label>Mountains</Label>
<ListBox ItemsSource="{Binding Path=Orders}"Name="lbDetails">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label VerticalAlignment="Center">OrderID:</Label>
<TextBlock Text="{Binding Path=OrderID}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Foreground="Green" VerticalAlignment="Center">CustID:</Label>
<TextBlock Text="{Binding Path=CustomerID}" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
</Window>
Window2.xaml.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Data.OleDb;
using System.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ATTest
{
///<summary>
/// Interaction logic for Window2.xaml///</summary>publicpartialclassWindow2 :Window{
publicOleDbConnection oleCon;publicOleDbCommand oleComd;string strSql ="SELECT * FROM Customers";public Window2(){
InitializeComponent();
BindData();
}
publicvoid BindData(){
string mdbFile = System.IO.Directory.GetCurrentDirectory() +"\\NWind.mdb";mdbFile = mdbFile.Replace(
"bin\\Debug\\","");oleCon =
newOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbFile);DataSet dtst =newDataSet();OleDbDataAdapter adpt =newOleDbDataAdapter();adpt.SelectCommand =
newOleDbCommand("SELECT * FROM Customers;", oleCon) ;adpt.Fill(dtst,
"Customers");lstEmployee.DataContext = dtst;
OleDbDataAdapter adpt2 =newOleDbDataAdapter();adpt2.SelectCommand =
newOleDbCommand("SELECT * FROM Orders;", oleCon);adpt2.Fill(dtst,
"Orders");DataTableCollection tables = dtst.Tables;dtst.Relations.Add(
"CustmerOrder",tables[
"Customers"].Columns["code"],tables[
"Orders"].Columns["CustomerID"]);sp.DataContext = dtst.Tables[
"Orders"];}
}
}

