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);
}
}