This is a migrated thread and some comments may be shown as answers.

Search Box

2 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Iron
Veteran
Claude asked on 14 Jan 2021, 06:21 PM

When I type text in the search box, several non-matching rows are selected.  The number that shows to the right in the search box, but the actual number of rows selected is wrong.  I am using the following event code to get the selected rows. I am writing the number of rows selected to the console.  I have attached a screenshot of the issues.

 private void TableSearchRow_SearchProgressChanged(object sender, SearchProgressChangedEventArgs e)
        {
            GridViewSearchRowInfo searchRow = sender as GridViewSearchRowInfo;

            if (e.SearchFinished && searchRow.CurrentSearchResultsCount > 0)
            {
                foreach (GridSearchResultCellInfo cellInfo in e.Cells)
                {
                    cellInfo.RowInfo.IsSelected = true;
                }
            }
            Console.WriteLine(dgvFiles.SelectedRows.Count().ToString());
        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Jan 2021, 09:54 AM
Hello, Claude, 

The provided code snippet is greatly appreciated. I was able to observe the undesired selected rows once the search operation is complete. Please have in mind that when you type a single letter in the search box, you mark all search result rows as selected. The next entered letter will narrow down the search result and you will mark the new search results as selected as well. However, the previously marks selected rows are still selected. I haven't noticed any code for clearing the selection.

That is why I have made the following modification to your code and the achieved result is illustrated in the attached gif file: 
        private void TableSearchRow_SearchProgressChanged(object sender, SearchProgressChangedEventArgs e)
        { 
            GridViewSearchRowInfo searchRow = sender as GridViewSearchRowInfo;

            if (e.SearchFinished && searchRow.CurrentSearchResultsCount > 0)
            {
                this.radGridView1.ClearSelection();
                foreach (GridSearchResultCellInfo cellInfo in e.Cells)
                {
                    cellInfo.RowInfo.IsSelected = true;
                }
            }
        }
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Claude
Top achievements
Rank 1
Iron
Veteran
answered on 18 Jan 2021, 05:26 PM
Works perfect, thank you
Tags
GridView
Asked by
Claude
Top achievements
Rank 1
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Claude
Top achievements
Rank 1
Iron
Veteran
Share this question
or