WPF cascaded combo
-
Hi, I am using LINQ to SQL and MVVM pattern in my application where i am retrieving my data by the following query:
internal ObservableCollection<INVCategory> GetCategoryList()
{
DataLoadOptions dataLoadOptions = new DataLoadOptions();
dataLoadOptions.LoadWith<INVCategory>(t => t.INVSubCategories);
this.Context.LoadOptions = dataLoadOptions;var categories = from category in this.Context.INVCategories orderby category.CatgeoryId descending select category; return new ObservableCollection<INVCategory>(categories.ToList());
}
And my XAML code for parent(Category) combo is:
<ComboBox Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="0" x:Name="categoryComboBox" ItemsSource="{Binding CategoryList}" IsEditable="True" DisplayMemberPath="CategoryName" SelectedValuePath="CatgeoryId" SelectedItem="{Binding CategoryList, Mode=TwoWay}" SelectedValue="{Binding Path=CurrentEntity.CategoryId, Mode=TwoWay}">
</ComboBox>for child(Subcategory) combo i am using:
<ComboBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="1" ItemsSource="{Binding SelectedItem, ElementName=categoryComboBox, Mode=OneWay}" DisplayMemberPath="SubCategoryName" SelectedValuePath="SubCategoryId" SelectedItem="{Binding INVSubCategories, Mode=TwoWay}" >
</ComboBox>But my child combo items is not populated during form loading as well as parent combo's selection changed though my parent combo items are populated. i can't figure out why my child combo is not functioning based on parent combo's selected item ,please help me.
-
Hi, I am using LINQ to SQL and MVVM pattern in my application where i am retrieving my data by the following query:
internal ObservableCollection<INVCategory> GetCategoryList()
{
DataLoadOptions dataLoadOptions = new DataLoadOptions();
dataLoadOptions.LoadWith<INVCategory>(t => t.INVSubCategories);
this.Context.LoadOptions = dataLoadOptions;var categories = from category in this.Context.INVCategories orderby category.CatgeoryId descending select category; return new ObservableCollection<INVCategory>(categories.ToList());
}
And my XAML code for parent(Category) combo is:
<ComboBox Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="0" x:Name="categoryComboBox" ItemsSource="{Binding CategoryList}" IsEditable="True" DisplayMemberPath="CategoryName" SelectedValuePath="CatgeoryId" SelectedItem="{Binding CategoryList, Mode=TwoWay}" SelectedValue="{Binding Path=CurrentEntity.CategoryId, Mode=TwoWay}">
</ComboBox>for child(Subcategory) combo i am using:
<ComboBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="1" ItemsSource="{Binding SelectedItem, ElementName=categoryComboBox, Mode=OneWay}" DisplayMemberPath="SubCategoryName" SelectedValuePath="SubCategoryId" SelectedItem="{Binding INVSubCategories, Mode=TwoWay}" >
</ComboBox>But my child combo items is not populated during form loading as well as parent combo's selection changed though my parent combo items are populated. i can't figure out why my child combo is not functioning based on parent combo's selected item ,please help me.
I think you are more likely to get an answer posting this on the WPF forum instead of the SQL forum. But I experienced basically the same thing and finally wrote my own code the old-fashioned way to populate the child table. Though, looking at your XAML you've pretty much setup a logical binding between the two. Good luck.
-
Hi, I am using LINQ to SQL and MVVM pattern in my application where i am retrieving my data by the following query:
internal ObservableCollection<INVCategory> GetCategoryList()
{
DataLoadOptions dataLoadOptions = new DataLoadOptions();
dataLoadOptions.LoadWith<INVCategory>(t => t.INVSubCategories);
this.Context.LoadOptions = dataLoadOptions;var categories = from category in this.Context.INVCategories orderby category.CatgeoryId descending select category; return new ObservableCollection<INVCategory>(categories.ToList());
}
And my XAML code for parent(Category) combo is:
<ComboBox Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="0" x:Name="categoryComboBox" ItemsSource="{Binding CategoryList}" IsEditable="True" DisplayMemberPath="CategoryName" SelectedValuePath="CatgeoryId" SelectedItem="{Binding CategoryList, Mode=TwoWay}" SelectedValue="{Binding Path=CurrentEntity.CategoryId, Mode=TwoWay}">
</ComboBox>for child(Subcategory) combo i am using:
<ComboBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="1" ItemsSource="{Binding SelectedItem, ElementName=categoryComboBox, Mode=OneWay}" DisplayMemberPath="SubCategoryName" SelectedValuePath="SubCategoryId" SelectedItem="{Binding INVSubCategories, Mode=TwoWay}" >
</ComboBox>But my child combo items is not populated during form loading as well as parent combo's selection changed though my parent combo items are populated. i can't figure out why my child combo is not functioning based on parent combo's selected item ,please help me.
I was sitting out on my porch having lunch when I realized what your problem may be. I remember there was a property (don't know it right now .. you'll have to search for the obvious in your XAML) which was basically binding to an event to tell the control when to rebind it's data. You need to find that property and bind it to the combobox SelectionChanged event.