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

  • SEARCH
  • Home
  • 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 8480099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:12:37+00:00 2026-06-10T19:12:37+00:00

I have Datagrid and Text Box in my Form. Datagrid is showing me existing

  • 0

I have Datagrid and Text Box in my Form. Datagrid is showing me existing items in my stock. I use Text Box to search and set focus to that row which is matching with my Text Box. Now it is working fine when VirtualizingStackPanel.IsVirtualizing=”false” but it is very slow and getting a lot RAM resource.
Here is my code for this.

public IEnumerable<Microsoft.Windows.Controls.DataGridRow> GetDataGridRows(Microsoft.Windows.Controls.DataGrid grid)
        {
            var itemsSource = grid.ItemsSource as IEnumerable;
            if (null == itemsSource) yield return null;
            foreach (var item in itemsSource)
            {
                var row = grid.ItemContainerGenerator.ContainerFromItem(item) as Microsoft.Windows.Controls.DataGridRow;
                if (null != row) yield return row;
            }
        }


        private void SearchBoxDataGrid_TextChanged(object sender, TextChangedEventArgs e)
        {
            var row = GetDataGridRows(AssortDataGrid);
            /// go through each row in the datagrid
            foreach (Microsoft.Windows.Controls.DataGridRow r in row)
            {
                DataRowView rv = (DataRowView)r.Item;
                // Get the state of what's in column 1 of the current row (in my case a string)
                string t = rv.Row["Ассортимент"].ToString().ToLower();
                if (t.StartsWith(SearchBoxDataGrid.Text.ToLower()))
                {
                    AssortDataGrid.SelectedIndex = r.GetIndex();
                    AssortDataGrid.ScrollIntoView(AssortDataGrid.SelectedItem);
                    break;
                }

            }
        }

What I want is to make it VirtualizingStackPanel.IsVirtualizing=”true” but in this case my method is not working. I know why it is not working, my code will work only for showing part of Datagrid.
What do you recommend? How to fix this issue? Any idea will be appreciated. If you give any working code it will be fantastic. I hope I could explain my problem.

  • 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-10T19:12:39+00:00Added an answer on June 10, 2026 at 7:12 pm

    I did a little coding and make it work. If anyone needs it in future please, use it.
    Firstly I am creating List of Products

    List<string> ProductList;
    

    Then on Load Method I list all my products to my Product List.

        SqlCommand commProc2 = new SqlCommand("SELECT dbo.fGetProductNameFromId(ProductID) as ProductName from Assortment order by ProductName desc", MainWindow.conn);
        string str2;
        SqlDataReader dr2 = commProc2.ExecuteReader();
        ProductList = new List<string>();
        try
        {
            if (dr2.HasRows)
            {
                while (dr2.Read())
                {
                    str2 = (string)dr2["ProductName"];
                    ProductList.Insert(0, str2.ToLower ());
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("An error occured while trying to fetch data\n" + ex.Message);
        }
    
        dr2.Close();
        dr2.Dispose(); 
    

    After that I did some changes in SearchBoxDataGrid_TextChanged

        private void SearchBoxDataGrid_TextChanged(object sender, TextChangedEventArgs e)
        {
    
            int pos = 0;
            string typedString = SearchBoxDataGrid.Text.ToLower();
            foreach (string item in ProductList)
            {
                if (!string.IsNullOrEmpty(SearchBoxDataGrid.Text))
                {
                    if (item.StartsWith(typedString))
                    {
                        pos = ProductList.IndexOf(item);
                        AssortDataGrid.SelectedIndex = pos;
                        AssortDataGrid.ScrollIntoView(AssortDataGrid.SelectedItem);
                        break;
                    }
                }
            }
    
        }
    

    Now it works when VirtualizingStackPanel.IsVirtualizing=”true”.
    That is all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGrid that represents layers - each row is an image on
I have a form that consists of two data grids and a button. Datagrid
QI have a jQuery function that causes my datagrid search results to be scrollable.
I have a datagrid where some of the text needs to span multiple columns.
Can i add two header text in Datagrid? My Requirement is to have two
I have datagrid whichs items source is domainDataSource. How i can refresh Domain data
I have a datagrid and I want to set the value of a dropdownlist
I have a combo box and a datagrid in my page. when the user
I have a Windows form that's generated using code (including buttons and what not).
Here are my requirements: I have a dropdown list and text box (appName and

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.