Could you please provide more information on this?
6 Answers, 1 is accepted
Thank you for writing.
To search in RadGridView control in hierarchy mode you can use ChildRows collection. Here is a simple example:
private List<GridViewRowInfo> Find(string text){ List<GridViewRowInfo> found = new List<GridViewRowInfo>(); Stack<GridViewChildRowCollection> rowStack = new Stack<GridViewChildRowCollection>(); rowStack.Push(this.radGridView1.ChildRows); while (rowStack.Count > 0) { GridViewChildRowCollection rows = rowStack.Pop(); foreach (var row in rows) { foreach (var col in this.radGridView1.Columns) { if (row.Cells[col.Index].Value == text) { found.Add(row); } } if (row.ChildRows.Count > 0) { rowStack.Push(row.ChildRows); } } } return found;}I hope this helps. Let me know if you need further assistance.
Greetings,Julian Benkov
the Telerik team
SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).
This is only working on the first 2 levels of my hierarchy grid. I can have 4 levels in total on my grid.
So when I search for a text that is present on my 3rd level, the search returns nothing.
Below is the relation I've made for my grid:
this.radGridView.Relations.AddSelfReference(this.radGridView.MasterTemplate, "pLevel", "parentId");
As my grid can have 4 levels I implemented as follows:
pLevel will contain the ID of the current level.
parentId will contain the ID of the parent.
Am I doing something wrong in my relation? Or do I need to add something extra to the "Find" function Julian?
The current Find method implementation depends on the root level Columns collection. You can extend it to support the inner hierarchy level for which another template with different columns schema is used. Here is a new implementation:
private List<GridViewRowInfo> Find(string text) { List<GridViewRowInfo> found = new List<GridViewRowInfo>(); Stack<GridViewChildRowCollection> rowStack = new Stack<GridViewChildRowCollection>(); rowStack.Push(this.gridView.ChildRows); while (rowStack.Count > 0) { GridViewChildRowCollection rows = rowStack.Pop(); foreach (var row in rows) { GridViewColumnCollection columns = row.ViewTemplate.Columns; foreach (var col in columns) { if (row.Cells[col.Index].Value.ToString() == text) { found.Add(row); } } if (row.ChildRows.Count > 0) { rowStack.Push(row.ChildRows); } } } return found; }The self-reference hierarchy mode does not depend on this change and the previous implementation should work without any issues. Please verify your data for level availability and search criteria.
I hope this helps.
Julian Benkov
the Telerik team
Hi,
This is working fine only for the first row of the hierarchy, if we provide the text that is matching
the data in the rows from the second level then it is not retuning all the rows of the hierarchy.
Please provide the solution which can return the rows(complete hierarchy) if the text matches with any cell with in the hierarchy.
Thanks
Muralidhar
The provided solution will return all rows from any level that contain the searched text, but will not include the parent row for every found row in the loop. If you want to get the parent row of a found row, you can use Parent property of GridViewRowInfo. If this does not help, please give us a more details about your scenario and what you want to achieve in the UI using this Find method. You can also send us a sample application to investigate it locally and find best solution for you. Please note that you have to open a new support ticket in order to be able to attach your project.
I am looking forward to your reply.
Julian Benkov
the Telerik team
Private Sub FindRow(match As String) If gridView.CurrentRow Is Nothing Then Return Dim iCol As Integer Dim iStartRow As Integer If gridView.CurrentCell IsNot Nothing Then iCol = gridView.CurrentCell.ColumnIndex iStartRow = gridView.CurrentCell.RowIndex + 1 End If Dim rows As GridViewChildRowCollection If gridView.CurrentRow.Parent IsNot Nothing Then 'somewhat circular reference in order to find the appropriate row collection of siblings of the selected row rows = gridView.CurrentRow.Parent.ChildRows Else rows = gridView.ChildRows End If 'For Each row As GridViewRowInfo In rows Dim row As GridViewRowInfo For iRow As Integer = iStartRow To rows.Count - 1 row = rows(iRow) If row.Cells(iCol).Value IsNot Nothing _ AndAlso row.Cells(iCol).Value.ToString().StartsWith(match) Then gridView.CurrentRow = row Return End If Next End SubSo this will only search within the context of the current table level... basically the row's siblings only... and in my case will move the user's selection to that row.