I created a side panel to search in several databases, which are selected from a combobox in the main menu.
<UserControl x:Class="Sum.SideRecordSearch"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Name="Search_Mode">
<UserControl.Resources>
<ResourceDictionary>
<xcdg:DataGridCollectionViewSource x:Key="Record_Search_DGCVS"
Source="{Binding ElementName=Search_Mode, Path=dataSet}"
AutoCreateItemProperties="True"
AutoCreateForeignKeyDescriptions="True"
DefaultCalculateDistinctValues="False"/>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<xcdg:DataGridControl x:Name="Search_Record"
ItemsSource="{Binding Source={StaticResource Record_Search_DGCVS} }"
ReadOnly="True"/>
</Grid>
I populated the data the first time I run the application with the following code:
public partial class SideRecordSearch : UserControl
{
public DataTable dataSet
{
get;
set;
}
public SideRecordSearch(MainWindow Window)
{
this.dataSet = getData(Window.System_Selected);
InitializeComponent();
}
internal void Change_System_Subsystem(string System_Selected)
{
this.dataSet = getData(System_Selected);
Search_Record.Items.Refresh();
}
}
And in the MainWindow class I put a void method each time the combobox is updated:
public partial class MainWindow : RibbonWindow
{
internal string System_Selected;
SideRecordSearch Search_Panel;
public MainWindow()
{
InitializeComponent();
System_Selected = ((ComboBoxItem)IP_System.SelectedItem).Name;
Search_Panel = new SideRecordSearch(this);
this.QuickPanel.Children.Add(Search_Panel);
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
System_Selected = ((ComboBoxItem)System.SelectedItem).Name;
Search_Panel.Change_System_Subsystem(System_Selected);
}
catch
{
}
}
}
However, if I change the combobox, the dataset gets updated, but the datagrid keeps showing the original items from the first time the dataset was filled.