Self Reference Hierarchy Custom Search

7 posts, 0 answers
  1. Arun Kumar
    Arun Kumar avatar
    60 posts
    Member since:
    Nov 2009

    Posted 05 Aug 2011 Link to this post

    Hi all,

    I want to highlight row based on text entered in the textbox. Basically I load data from database and show it on the grid with self reference hierarchy relation. Initially grid is collapsed to first level (I have more than 5 sub levels). How do I do that?

    Thanks
  2. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 10 Aug 2011 Link to this post

    Hello Arun,

    Thank you for your question.

    You can use ConditionalFormatting to highlight rows depending on a text in a textbox. Please review the following code snippet:
    ConditionalFormattingObject obj = new ConditionalFormattingObject("MyCondition", ConditionTypes.Contains, textBoxText, "", true);
    obj.CellForeColor = Color.Red;
    obj.RowBackColor = Color.SkyBlue;
    this.radGridView1.Columns[ColumnName].ConditionalFormattingObjectList.Add(obj);

    The formatting will apply to all level of self-reference hierarchy.

    Best regards,
    Alexander
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Arun Kumar
    Arun Kumar avatar
    60 posts
    Member since:
    Nov 2009

    Posted 11 Aug 2011 Link to this post

    Hello Alexander,

    Thanks for your reply. Its working fine but I want to expand rows to that row. I am tried with the following code but it takes more time to expand rows. The reason is it expands all rows instead of its child rows. Can you give me some idea to achieve this? 

    For Each gvr As GridViewRowInfo In Me.dgv.MasterTemplate.Rows
        gvr.IsExpanded = True
     
        If gvr.Cells("AcCode").Value.ToString() = Me.txtSearch.Text Or gvr.Cells("AcName").Value.ToString() = Me.txtSearch.Text Then
     
            Dim tableElement As GridTableElement = TryCast(Me.dgv.CurrentView, GridTableElement)
            gvr.IsSelected = True
     
            If Not tableElement Is Nothing Then
                tableElement.ScrollToRow(gvr)
            End If
     
            Exit For
        End If
    Next

    I would appreciate if you tell me how do I expand current selected row and its child rows?

    Thanks
  5. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 12 Aug 2011 Link to this post

    Hello Arun,

    You can use a recursive algorithm to search the child rows of each first-level row in the self-reference hierarchy. This algorithm expands only the parent rows of the found row:

    Private Sub FindRow()
        For Each Row As GridViewRowInfo In Me.radGridView1.MasterTemplate.Rows
            If Row.Cells("AcCode").Value.ToString() = Me.txtSearch.Text Then
                Row.IsCurrent = True
                Exit For
            End If
     
            Me.SearchChildRows(Row)
        Next
    End Sub
     
    Private Sub SearchChildRows(ByVal Row As GridViewRowInfo)
        For Each ChildRow As GridViewRowInfo In Row.ChildRows
            If ChildRow.Cells("AcCode").Value.ToString() = Me.txtSearch.Text Then
                ChildRow.IsCurrent = True
                Exit For
            End If
     
            Me.SearchChildRows(ChildRow)
        Next
    End Sub

    I hope it helps you to accomplish your requirements.

    Best regards,
    Alexander
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  6. Arun Kumar
    Arun Kumar avatar
    60 posts
    Member since:
    Nov 2009

    Posted 12 Aug 2011 Link to this post

    Thanks Alexander ,

    It solved my issue.
  7. Ed
    Ed avatar
    8 posts
    Member since:
    Apr 2010

    Posted 18 Aug 2011 Link to this post

    Thanks for your answer - it resolved my question too!
  8. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 18 Aug 2011 Link to this post

    Hi guys,

    I am glad to hear that you found my response helpful. Should you have additional questions, do not hesitate to contact me.

    All the best,
    Alexander
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top
UI for WinForms is Visual Studio 2017 Ready