title: Using INotifyPropertyChanged to refresh a databound datagrid?
body: <p>I have created a databound datagrid in WPF: 'ActionResults', when I run the application it shows the contents of the database table.</p>
  
  <p>The I.T dept. are going to manually update the 'ActionResult' table in SQL server management studio. If any changes are made to the table, they will display in the datagrid only after I restart the application. I would like to add an 'Update' button which will re-fresh the datagrid, displaying any changes made to the table.</p>
  
  <p>I was previously trying to do a hack with something like</p>
  
  <pre><code>actionResultsDataGrid.Items.Refresh();
  </code></pre>
  
  <p>but decided to go with the ObservableCollection. So I have been following the <a href="http://www.youtube.com/watch?v=7CKB44Mc4Q0" rel="nofollow">http://www.youtube.com/watch?v=7CKB44Mc4Q0</a> tutorial the only problem is he manually creates his records, where I will be using the db. Here is where I am so far:</p>
  
  <pre><code>//XAML
  &lt;Window x:Class="WpfApplication2.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:WpfApplication2" Loaded="Window_Loaded"&gt;
      &lt;Window.Resources&gt;
          &lt;CollectionViewSource x:Key="actionResultsViewSource" d:DesignSource="{d:DesignInstance my:ActionResult, CreateList=True}" /&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid DataContext="{StaticResource actionResultsViewSource}"&gt;
          &lt;DataGrid AutoGenerateColumns="True" EnableRowVirtualization="True" ItemsSource="{Binding}" Name="actionResultsDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" Margin="0,0,0,85"&gt;
              &lt;DataGrid.Columns&gt;
                  &lt;DataGridTextColumn x:Name="idColumn" Binding="{Binding Path=Id}" Header="Id" Width="SizeToHeader" /&gt;
                  &lt;DataGridTextColumn x:Name="actionColumn" Binding="{Binding Path=Action}" Header="Action" Width="SizeToHeader" /&gt;
          &lt;/DataGrid&gt;
          &lt;Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="388,253,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>I then created an ActionResult class which uses the INotifyPropertyChanged to update.</p>
  
  <pre><code>public class ActionResults : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged;
  
      private void NotifyPropertyChanged(string propertyName)
      {
          if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
  
      private int _Id;
      public int Id
      {
          get { return _Id; }
          set 
          { 
              _Id = value;
              NotifyPropertyChanged("Id");
          }
      }
  
      private string _Action;
      public string Action
      {
          get { return _Action; }
          set 
          { 
              _Action = value;
              NotifyPropertyChanged("Action");
          }
      }
  </code></pre>
  
  <p>and my button in the MainWindow.xaml.cs</p>
  
  <pre><code>private void button1_Click(object sender, RoutedEventArgs e)
  {
  
  }
  </code></pre>
  
  <p>My question being from following that tutorial he then creates another class 'ActionResults_' and manually adds records, but as I am using the db table. What do I do from here? please advise I am stuck. Where do the observable collections come into place?</p>
  
  <p>thank you</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>   private void Load_ActionResult_Table()
      {
          ActionResultsTable.ActionResultDataSet actionResultDataSet = ((ActionResultsTable.ActionResultDataSet)(this.FindResource("actionResultDataSet")));
          // Load data into the table ActionResult. You can modify this code as needed.
          ActionResultsTable.ActionResultDataSetTableAdapters.ActionResultTableAdapter actionResultDataSetActionResultTableAdapter = new ActionResultsTable.ActionResultDataSetTableAdapters.ActionResultTableAdapter();
          actionResultDataSetActionResultTableAdapter.Fill(actionResultDataSet.ActionResult);
          System.Windows.Data.CollectionViewSource actionResultViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("actionResultViewSource")));
          actionResultViewSource.View.MoveCurrentToFirst();
      }
  
    private void Refresh_Table_Button_Click(object sender, RoutedEventArgs e)
      {
         //SO DO I NEED TO SAY, SET TABLE TO NULL THEN RELOAD BY USING BELOW FUNCTION?
          Load_ActionResult_Table();
      }
  </code></pre>