Quantcast
Viewing all articles
Browse latest Browse all 18858

Combobox EntityFramework Parent-Child relationship

Hi,

What i have is two comboboxes, to display my my entities. these are ReasonCategory and ReasonCode.

I would like when the ReasonCategory combobox changes for the ReasonCode one to update.

Entity Framework has a top level ReasonCategory with and associated ReasonCode

Here is my code.

Imports System.Collections.ObjectModel Imports System.Threading.Tasks Imports WWCabinetRepair_DAL Namespace Views Public Class RepairHistoryViewModel Inherits ViewModelBase Private m_reasoncategories As ObservableCollection(Of ReasonCategory) Private m_repairhistory As RepairHistory = Nothing Private m_reasoncategoryviewsource As CollectionViewSource Private m_reasoncategoryview As ListCollectionView Private m_repairid As Integer = 0 Private m_context As New ShilohEntities Public Property ReasonAreaViewSource As CollectionViewSource Get Return m_reasoncategoryviewsource End Get Set(value As CollectionViewSource) m_reasoncategoryviewsource = value OnPropertyChanged("ReasonAreaViewSource") End Set End Property Public Property ReasonCategories As ObservableCollection(Of ReasonCategory) Get Return m_reasoncategories End Get Set(value As ObservableCollection(Of ReasonCategory)) m_reasoncategories = value OnPropertyChanged("ReasonCategories") End Set End Property Public Property RepairID As Integer Get Return m_repairid End Get Set(value As Integer) m_repairid = value End Set End Property Public Property ReasonAreaView As ListCollectionView Get Return m_reasoncategoryview End Get Set(value As ListCollectionView) m_reasoncategoryview = value End Set End Property Public Property RepairHistory As RepairHistory Get Return m_repairhistory End Get Set(value As RepairHistory) m_repairhistory = value End Set End Property Public Sub New(ByVal repairid As Integer) m_repairhistory = New RepairHistory() m_repairid = repairid ReasonCategories = New ObservableCollection(Of ReasonCategory)() m_reasoncategoryviewsource = New CollectionViewSource() m_reasoncategoryviewsource.Source = m_reasoncategories ReasonAreaView = CType(ReasonAreaViewSource.View, ListCollectionView) Dim _reasonareaquery = From rc In m_context.ReasonCategories Where rc.ReasonAreaID = m_repairid Select rc ReasonCategories = New ObservableCollection(Of ReasonCategory)(_reasonareaquery.ToList())

End Sub End Class End Namespace

and my xaml file

<UserControl x:Class="ucRepairHistory"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:dal="clr-namespace:WWCabinetRepair_DAL;assembly=WWCabinetRepair_DAL" mc:Ignorable="d" 
             Height="259" Width="360" Background="Transparent"><UserControl.Resources><CollectionViewSource x:Key="ReasonCategoryViewSource" Source="{Binding Path=ReasonCategories}" d:DesignSource="{d:DesignInstance dal:ReasonCategory,CreateList=True}"/><CollectionViewSource x:Key="ReasonHistoryViewSource" Source="{Binding Path=RepairHistory}"/></UserControl.Resources><Border CornerRadius="15" BorderBrush="White" Background="LightGray" BorderThickness="1,1,0,0"><Border.Effect><DropShadowEffect Color="Gray" Opacity="0.5"/></Border.Effect><Grid Background="LightGray" Margin="3"><Grid.RowDefinitions><RowDefinition Height="683*" /><RowDefinition Height="30" /></Grid.RowDefinitions><Grid Grid.Column="0"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="2*"/>                </Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="*"/></Grid.RowDefinitions><Label Grid.Row="0" Grid.Column="0" Content="Order #/Red #" HorizontalAlignment="Right" /><Label Grid.Row="1" Grid.Column="0" Content="Reason Category" HorizontalAlignment="Right" /><Label Grid.Row="2" Grid.Column="0" Content="Reason Code" HorizontalAlignment="Right" /><Label Grid.Row="3" Grid.Column="0" Content="Quantity" HorizontalAlignment="Right" /><Label Grid.Row="4" Grid.Column="0" Content="Comments" HorizontalAlignment="Right" /><TextBox Grid.Row="0" Grid.Column="1" Margin="2"/><ComboBox Name="cmbReasonCategory" Grid.Row="1" Grid.Column="1" Margin="2" ItemsSource="{Binding Source={StaticResource ReasonCategoryViewSource}}" DisplayMemberPath="CategoryDescription"/><ComboBox Name="cmbReasonCode" Grid.Row="2" Grid.Column="1" Margin="2" DisplayMemberPath="Description" ItemsSource="{Binding Path=ReasonCodes, ElementName=cmbReasonCategory}" /><xctk:IntegerUpDown HorizontalAlignment="Right" Width="100" Grid.Row="3" Grid.Column="1" Margin="2"/><TextBox Grid.Row="4" Grid.Column="1" Margin="2" /></Grid><StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right"><Button Name="btnOK" Width="72" Height="23" Margin="1,0" Click="btnOK_Click">_OK</Button><Button Name="btnCancel" Width="72" Height="23" Margin="1,0" Click="btnCancel_Click">_Cancel</Button></StackPanel></Grid></Border></UserControl>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>