title: How to select a row in datagrid from ViewModel in MVVM?
body: <p>I'm trying to validate user input in a datagrid, the way i'm doing it is like:</p>
  
  <p>I)  allow user to add a row</p>
  
  <p>II) allow user to fill some cells</p>
  
  <p>III)when EndEdit() event happens, I would update my Model</p>
  
  <p>IV) if Model could not be updated (for example when user didn't supply 
      NotNull values), an error is raised.</p>
  
  <p>V)  HERE IS THE TRICKY PART! I want to stay on the faulty row of the datagrid, but the high lightened row will change despite the fact that I've set SelectedIndex and SelectedValue correctly.</p>
  
  <p>here is my XAML:</p>
  
  <pre><code>&lt;DataGrid x:Name="gd_Contacts" SelectedItem="{Binding SelectedContact,Converter={StaticResource NewPlaceConverter}}" 
                SelectedIndex="{Binding SelectedItemIndex}"
                Margin="0,5,1,0" ItemsSource="{Binding ContactCollection, Mode=TwoWay}" 
                CanUserAddRows="True" CanUserDeleteRows="False" AutoGenerateColumns="False" Grid.Column="1"&gt;
  </code></pre>
  
  <p>Here is my ViewModel:</p>
  
  <pre><code>private ObservableCollection&lt;ActionEnabledContacts&gt; FContactCollection;
  //....
  public ActionEnabledContacts SelectedContact //THE PROPERTY FOR SELECTEDITEM
      {
          get { return FSelectedContact; }
          set 
          { 
              //
              List &lt;ActionEnabledContacts&gt; InvalidList=ContactCollection.Where&lt;ActionEnabledContacts&gt;(p =&gt; p.cnt_Key == 0).ToList();
              if (InvalidList != null &amp;&amp; InvalidList.Count &gt; 0)
              {
                  //now find index of that bastard
                  List&lt;ActionEnabledContacts&gt; AllContacts = ContactCollection.ToList();
                  int BastardIndex = 0;
                  foreach (ActionEnabledContacts AContact in AllContacts)
                  {
                      if (AContact.cnt_Key == 0)
                      {
                          FSelectedContact = InvalidList[0];
                          NotifyPropertyChanged();
                          SelectedItemIndex = BastardIndex;
                          //^^^^ THIS LINE DO UPDATE SELECTEDINDEX AND CALL NotifyPropertyChanged()
                      }
                      BastardIndex++;
                  }
              }
              else
              {
                  //
                  FSelectedContact = value;
                  NotifyPropertyChanged();
              }
          }
      }
  </code></pre>