title: Problems with the selected index in the WPF DataGrid
body: <p>I have a <code>wpf</code> DataGrid. </p>
  
  <p>On DataGrid the selected index is bind to a variable sitting in ViewModel.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>&lt;DataGrid DataContext="{Binding MyViewModel}" SelectedIndex="{Binding SelectedXIndex,Mode=TwoWay}"  ItemsSource="{Binding xList, Mode=TwoWay}" AutoGenerateColumns="False" GridLinesVisibility="Horizontal"&gt;
      &lt;DataGrid.Columns&gt;
        ...
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>In ViewModel I have a list of items from class X (Observable Collection), and I have the selected index variable:</p>
  
  <pre><code>    private int _selectedXIndex;
      public int SelectedXIndex
      {
          get { return _selectedXIndex; }
          set
          {
              _selectedXIndex = value;
              NotifyPropertyChanged("SelectedXIndex");
          }
      }
  </code></pre>
  
  <p>When I click on an item in the DataGrid selected index changes, and when I initialize it in constractor of the ViewModel is changed in DataGrid, but when I initialize it on a certain function is changed only in the ViewModel and not in the DataGrid:</p>
  
  <pre><code>  public void MoveDown()
      {
          SelectedXIndex++;         
      }
  </code></pre>
  
  <p>I can not understand why this is happening!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I added to the function the following line of code:</p>
  
  <pre><code>xList[SelectedXIndex].Name = "Changest Name For Test";
  </code></pre>
  
  <p>and it works.</p>
  
  <p>He changes the name on the line that Selected Item of the model on it, but he did not show at DataGird that the selected item is the one.</p>