Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:42:10+00:00 2026-06-08T06:42:10+00:00

I have a datagrid which the user can add records to. If a certain

  • 0

I have a datagrid which the user can add records to.
If a certain item already exists, I want to scroll to the relevant row and highlight it.

I can’t find how to enumerate the rows in the datagrid, I know how to find the item in the observable collection, but can’t find how to find the relevant row.

Also, highlight tips would be welcome, I haven’t done animations at all yet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:42:11+00:00Added an answer on June 8, 2026 at 6:42 am

    I created a sample application to check whether newly added item already exists in datagrid or not. If it exists then select it and scroll into view that row. I didnot write for the condition where newly added item doesnot exist in datagrid.

    <my:DataGrid x:Name="PersonsDataGrid" AutoGenerateColumns="False" Loaded="PersonsDataGrid_Loaded" LoadingRow="PersonsDataGrid_LoadingRow">
      <my:DataGrid.Columns>
        <my:DataGridTextColumn Binding="{Binding FirstName}"  Header="First Name"/>
        <my:DataGridTextColumn Binding="{Binding LastName}" Header="Last Name"/>
      </my:DataGrid.Columns>
    
    </my:DataGrid>  
    
    namespace DataGridDemo  
    {  
     public partial class MainPage : UserControl  
      {  
    
     private int selectedIndex = 0;
     private DataGridRow selectedRow = null;
        public MainPage()  
        {  
      InitializeComponent();  
      Persons = new List<Person>();
    
      Persons.Add(new Person(){FirstName = "Tony1", LastName = "Smith"});
      Persons.Add(new Person() { FirstName = "Jennifer1", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony2", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer2", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony3", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer3", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony4", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer4", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony5", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer5", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony6", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer6", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony7", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer7", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony8", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer8", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony9", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer9", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony10", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer10", LastName = "Suze" });
    
      Persons.Add(new Person() { FirstName = "Tony11", LastName = "Smith" });
      Persons.Add(new Person() { FirstName = "Jennifer11", LastName = "Suze" });
    
      PersonsDataGrid.ItemsSource = Persons;
    }
    
    
    private void PersonsDataGrid_Loaded(object sender, RoutedEventArgs e)
    {
      Person newPerson = new Person() { FirstName = "Tony10", LastName = "Smith" };
    
      Person p = (from item in Persons
                  where item.FirstName == newPerson.FirstName && item.LastName==newPerson.LastName
                  select item).FirstOrDefault();
    
    
      if(p!=null)
      {
        selectedIndex = Persons.IndexOf(p);
    
        if (selectedIndex >= 0)
        {
          //PersonsDataGrid.SelectedIndex = selectedIndex ; - sometimes if selecteditem doesnot work
          PersonsDataGrid.SelectedItem = p;
          PersonsDataGrid.Dispatcher.BeginInvoke(() =>
                                                   {
                                                     PersonsDataGrid.ScrollIntoView(p,null);
                                                   });
        }
      }
    
    }
    
     private void PersonsDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
    {
      DataGridRow row = e.Row as DataGridRow;
    
      if (row.GetIndex() == selectedIndex)
      {
        selectedRow = row;
      }
    
    }
    
    
    public List<Person> Persons { get; set; }
    }
    
    public class Person  
    {
    
    public string FirstName { get; set; }
    
    public string LastName { get; set; }
    
    
    } 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program in which a user selects a row in a Datagrid
I have a dataGrid(not dataGridView) in which i need to add Checkbox dynamically at
I have I datagrid, on which I want to select multiple rows on a
I have a datagrid which I am using LINQ to fill, I then add
I have a DataGrid , which is bound to a DataTable object. The user
I have a top-level menu item which is responsible for refreshing a datagrid in
I want to create a user control, which can be bound to some data
Quick question regarding the Compact Framework DataGrid. How can I scroll a particular row
I have a datagrid which is populated with CSV data when the user drag/drops
I have ObservableCollection<IInterface> which is binded to DataGrid. IInterface is interface. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.