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

SearchTextRow to use Startwith vs. Contains

4 Answers 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 30 Jul 2019, 03:19 PM

Hi

Is there a way to make SearchText to do "StartWith" vs. its default "Contains".

Thank you,

P.S. I am not referring to Filters.

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 31 Jul 2019, 02:15 PM
Hello, Boris,

By default, RadGridView searches for cell values that contain that search criteria. If you need to change the comparison logic to be StartsWith, you need to create custom GridViewSearchRowInfo. Subscribe to the CreateRowInfo event at design time and use the following code snippet:

private void radGridView1_CreateRowInfo(object sender, GridViewCreateRowInfoEventArgs e)
{
    if (e.RowInfo is GridViewSearchRowInfo)
    {
        e.RowInfo = new CustomSearchRow(e.ViewInfo);
    }
}
 
public class CustomSearchRow : GridViewSearchRowInfo
{
    public CustomSearchRow(GridViewInfo viewInfo) : base(viewInfo)
    {
    }
 
    protected override bool MatchesSearchCriteria(string searchCriteria, GridViewRowInfo row, GridViewColumn col)
    {
        return (row.Cells[col.Name].Value + "").StartsWith(searchCriteria);
    }
}

Note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread. Thank you for your understanding.

I hope this information helps. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Boris
Top achievements
Rank 1
answered on 31 Jul 2019, 08:19 PM

Thank you Very much for Reply,

But i don't think its working, its still behaves like before.

following line was added to .designer file as well:

this.radGV.CreateRowInfo += new Telerik.WinControls.UI.GridViewCreateRowInfoEventHandler(this.radGridView1_CreateRowInfo);

Thank you,

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Aug 2019, 06:07 AM
Hello, Boris, 

As it was previously noted, it is necessary to subscribe to the CreateRowInfo event at design time in order to replace the GridViewSearchRowInfo with the custom one. 

I have attached my sample project for your reference. Could you please give it a try and see how it works on your end?

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Boris
Top achievements
Rank 1
answered on 05 Aug 2019, 01:56 PM

Thank you very much.

Issue was i was running previews version, as soon as I updated to latest. Its started to work. 

Tags
GridView
Asked by
Boris
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Boris
Top achievements
Rank 1
Share this question
or