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
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?
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?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
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?
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?
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?
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?
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
