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

row searched grid losing position.

9 Answers 51 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 15 Mar 2016, 06:21 PM

I have a grid bound to claimantBindingSource in which I have enabled row searching.

The search returns 3 matches, I move to the second match.

After executing the code below the bindingSource is moving to the first match which is a huge issue.

Is there any way to keep the position on the second match?

 

 claimantDrv = this.claimantBindingSource.Current as DataRowView;

 var Claimant = claimantDrv.Row as CRSDataSet.claimantRow;
 fullname = "some name";
 Claimant.name = fullname;

 

 

 

 

9 Answers, 1 is accepted

Sort by
0
Sam
Top achievements
Rank 1
answered on 15 Mar 2016, 06:45 PM

Sorry, 

Searching by name, so the position is moving because the name changed.

That said is there anyway to prevent the row from moving if the underlying value changes?

0
Sam
Top achievements
Rank 1
answered on 15 Mar 2016, 08:27 PM

Okay

RadGridView.MasterView.TableSearchRow.AutomaticallySelectFirstResult = false;

Gets me where I need to go, however how can I turn it back on only when the user enters a value into the Search Box?
0
Accepted
Hristo
Telerik team
answered on 16 Mar 2016, 03:02 PM
Hello Sam,

Thank you for writing.

You can handle the TextChanged event of the search and if the text is empty set the AutomaticallySelectFirstResult property to false. Please check my code snippet below:
public Form1()
{
    InitializeComponent();
 
    this.radGridView1.DataSource = this.GetData();
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
    this.radGridView1.AllowSearchRow = true;
 
    this.radGridView1.ViewCellFormatting += radGridView1_ViewCellFormatting;
}
 
private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    GridSearchCellElement cell = e.CellElement as GridSearchCellElement;
    if (cell != null)
    {
        cell.SearchTextBox.TextChanged -= SearchTextBox_TextChanged;
        cell.SearchTextBox.TextChanged += SearchTextBox_TextChanged;
    }
}
 
private void SearchTextBox_TextChanged(object sender, EventArgs e)
{
    GridSearchCellTextBoxElement searchTextBox = (GridSearchCellTextBoxElement)sender;
    if (searchTextBox.Text != "")
    {
        this.radGridView1.MasterView.TableSearchRow.AutomaticallySelectFirstResult = true;
    }
    else
    {
        this.radGridView1.MasterView.TableSearchRow.AutomaticallySelectFirstResult = false;
    }
}
 
private DataTable GetData()
{
    DataTable dt = new DataTable();
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Date", typeof(DateTime));
    dt.Columns.Add("Bool", typeof(bool));
    dt.Columns.Add("Description", typeof(string));
    for (int i = 0; i < 20; i++)
    {
        dt.Rows.Add(i, "Name " + i, DateTime.Now.AddDays(i), i % 2 == 0 ? true : false, "Description " + i);
    }
 
    return dt;
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Sam
Top achievements
Rank 1
answered on 16 Mar 2016, 03:11 PM
Awesome Thanks!
0
Piumi
Top achievements
Rank 1
answered on 10 Dec 2017, 01:44 PM

Hi Hristo,

It worked for me also, Thanks.

I want to make the Search text box clear in a button_click or when user click on cell of the grid?

could you please help to solve this?

0
Piumi
Top achievements
Rank 1
answered on 10 Dec 2017, 01:45 PM
Hi Hristo,
It worked for me also, Thanks.
I want to make the Search text box clear in a button_click or when user click on cell of the grid?
could you please help to solve this?
0
Piumi
Top achievements
Rank 1
answered on 10 Dec 2017, 01:45 PM
Hi Hristo,
It worked for me also, Thanks.
I want to make the Search text box clear in a button_click or when user click on cell of the grid?
could you please help to solve this?
0
Piumi
Top achievements
Rank 1
answered on 10 Dec 2017, 01:46 PM
Hi Hristo,
It worked for me also, Thanks.
I want to make the Search text box clear in a button_click or when user click on cell of the grid?
could you please help to solve this?
0
Hristo
Telerik team
answered on 11 Dec 2017, 02:54 PM
Hello Piumi,

Thank you for writing.

You can clear the search criteria by calling the search method and passing null as a parameter: 
this.radGridView1.MasterView.TableSearchRow.Search(null);

I hope this helps. Let me know if you need further assistance.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Sam
Top achievements
Rank 1
Answers by
Sam
Top achievements
Rank 1
Hristo
Telerik team
Piumi
Top achievements
Rank 1
Share this question
or