Completed
Last Updated: 13 Mar 2015 14:31 by ADMIN
ADMIN
Dimitar
Created on: 17 Oct 2014 09:58
Category: GridView
Type: Bug Report
0
FIX. RadGridView - when the search is enabled and the grid is refreshed the matched items formatting is not reset.
To reproduce:
- Enable the search row in the grid.
- Enter some text in the search text box in order to mark some rows.
- Refresh the master template.
- Notice that the text is cleared, but the formatting remains.

Workaround, use the following custom cell:

      class MyGridSearchCellElement : GridSearchCellElement
        {
            public MyGridSearchCellElement(GridViewColumn column, GridRowElement row)
                :base (column, row)
            {

            }
            bool performSearch = true;
            protected override void SyncLabelText()
            {
                //base.SyncLabelText();

                GridViewSearchRowInfo searchRow = this.RowInfo as GridViewSearchRowInfo;

                if (searchRow == null)
                {
                    return;
                }

                performSearch = false;

                string searchCriteria = typeof(GridViewSearchRowInfo).GetField("searchCriteria", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(searchRow).ToString();

                if (string.IsNullOrEmpty(searchCriteria))
                {
                    this.SearchTextBox.Text = String.Empty;
                    this.SearchTextBox.SearchInfoLabel.Text = String.Empty;
                }
                else
                {
                    this.SearchTextBox.Text = searchCriteria;
                    this.SearchTextBox.SearchInfoLabel.Text = string.Format("{0} {1} {2}", searchRow.CurrentResultIndex + 1, Telerik.WinControls.UI.Localization.RadGridLocalizationProvider.CurrentProvider.GetLocalizedString(Telerik.WinControls.UI.Localization.RadGridStringId.SearchRowResultsOfLabel), searchRow.CurrentSearchResultsCount);
                }

                performSearch = true;
            }

            protected override void Search()
            {
                if (!performSearch)
                {
                    return;
                }

                base.Search();
            }
        }


To put it in action, use the CreateCell event of RadGridView:
 void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
        {
            if (e.CellType == typeof( GridSearchCellElement))
            {
                e.CellElement = new MyGridSearchCellElement(e.Column, e.Row);
            }
        }
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
2 comments
ADMIN
Stefan
Posted on: 13 Mar 2015 14:31
To clarify, the issue in Nisha's case was because she is using a custom implementation of GridViewSearchRowInfo, and in this case, the default type should be specified:

string searchCriteria = typeof(GridViewSearchRowInfo).GetField("searchCriteria", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(searchRow).ToString();

I have updated the workaround with this information.
Nisha
Posted on: 10 Mar 2015 08:54
Hi Dimitar ,

Thanks for the reply. Unfortunately we are not in situation to upgrade the telerik version, so I have followed the solution provided in case page , it works well on the sample project i created but it is not working in the actual solution. 
I am getting error in the following line 
string searchCriteria = searchRow.GetType().GetField("searchCriteria", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(searchRow).ToString();


when i go into the detail of it,  searchRow.GetType() has a value but when i type in GetField("searchCriteria"), it give me null value. 

Please provide any suggestions, as i am stuck with error

Thanks & Regards,
Nisha
Attached Files: