title: How to scroll to the selected row in the grid of listview in WPF
body: <p>I have written a code to switch from list view to gallery view, vice-versa. The item selected in listview gets selected in galleryview too when switched to it and vice-versa. Now when switching to listview the item gets selected but control does not scrolls to that particular row. We have to scroll manually. I want it to be scrolled to the selected row automatically when switched.</p>
  
  <pre><code>     private void GallerySearchResults_SelectionChanged(object sender, System.EventArgs e)
      {
          if (GallerySearchResults.SelectedSearchItem != null)
              SelectedRecordIndex = GallerySearchResults.SelectedSearchItem.IndexNo;
  
          SelectedSearchItem = GallerySearchResults.SelectedSearchItem; 
  
  
      }
      private void ListSearchResults_SelectionChanged(object sender, System.EventArgs e)
      {
  
          if (ListSearchResults.SelectedSearchItem != null)
              SelectedRecordIndex = ListSearchResults.SelectedSearchItem.IndexNum;
          SelectedSearchItem = ListSearchResults.SelectedSearchItem; 
      }
      private void SetSelectedItemOnViewChange()
      {
          if (SelectedViewMode.ModeName == ViewModes[1].ModeName)
              GallerySearchResults.SelectedSearchItem = GallerySearchResults.GalleryItems.FirstOrDefault((x =&gt; x.IndexNo == SelectedRecordIndex));
  
  
          else if (SelectedViewMode.ModeName == ViewModes[0].ModeName)
              ListSearchResults.SelectedSearchItem = ListSearchResults.ListItems.FirstOrDefault((x =&gt; x.IndexNum == SelectedRecordIndex));
  
      } 
  </code></pre>