How to Display Custom Data in 'RadGrid Header Item'?

7 posts, 0 answers
  1. D.SRINIVASA
    D.SRINIVASA avatar
    34 posts
    Member since:
    Oct 2010

    Posted 09 Jul 2011 Link to this post

    Hi,

    i am Srinivas,

    Here in my Project i have a RadGrid View and RadTree view  to display  data from Backend Table. Here i have a problem to display the Header Item for RadGrid. In RadTree View when i checked the RadTree Node Then automatically RadGrid View to Display the Data from Backend. Here i was used the filter concept in RadGrid.
    the following is the code for filter concept..

    b0.Text = "lot_id [Lot ID] Group By lot_id"
    Dim expression1 As GridGroupByExpression = GridGroupByExpression.Parse(b0.Text)
            CustomizeExpression(expression1)
    Me.RadGrid1.MasterTableView.GroupByExpressions.Add(expression1)

     Private Sub CustomizeExpression(ByVal expression As GridGroupByExpression)
            Dim existing As GridGroupByField = expression.SelectFields.FindByName("lot_id")
            If existing Is Nothing Then
            Else
                'field is present then set a format string
                existing.FormatString = "{0:C}"
            End If
        End Sub
    the above code working fine as per my output  in 1st attachment (1.JPG) .
    and next
    Following code i used in Rad Grid Item Data Bound for Header Item display:
    'Group(heading)
    If TypeOf e.Item Is GridGroupHeaderItem Then
    Dim item As GridGroupHeaderItem = DirectCast(e.Item, GridGroupHeaderItem)
    Dim groupDataRow As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
    Dim nodeCollection As IList(Of RadTreeNode)
    item.DataCell.Text = ""
    For Each column As DataColumn In groupDataRow.DataView.Table.Columns
    If column.ColumnName = "lot_id" Then
    nodeCollection = RadTreeView1.CheckedNodes
    For Each node As RadTreeNode In nodeCollection
    header.Text = ""
    header.Text += node.FullPath + "<br/>"
    item.DataCell.Text = header.Text
    Next
    End If
    Next
    End If

    But, when i checked the second check box in tree node along with first node, here Backend data displaying fine but coming for RadHeaderItem for 001-Lot1 the header item is displaying like "AF-Angel Falls/P1-Phase1/002-Lot2
    Instead of this in my output should be with "AF-Angel Falls/P1-Phase1/001-Lot1
    Description for second attachment(2.JPG):

    Lot1 and Lot 2 data displaying fine as per second attachment,
    but the above  first Header Item Displaying "AF-Angel Falls/P1-Phase1/002-Lot2for Lot 1 details. it should be as bellow
    "AF-Angel Falls/P1-Phase1/001-Lot1" for Lot 1 details. 

    Please Help Me..

    Thanks 
    D.Srinivas
  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 14 Jul 2011 Link to this post

    Hello D.Srinivasa,

    Please try using the following code on ItemDataBound and let me know whether it helps:
    If TypeOf e.Item Is GridGroupHeaderItem Then
        Dim item As GridGroupHeaderItem = DirectCast(e.Item, GridGroupHeaderItem)
        Dim groupDataRow As DataRowView = DirectCast(e.Item.DataItem, DataRowView)
        Dim nodeCollection As IList(Of RadTreeNode)
        item.DataCell.Text = ""
        For Each column As DataColumn In groupDataRow.DataView.Table.Columns
            If column.ColumnName = "lot_id" Then
                item.DataCell.Text = RadTreeView1.CheckedNodes(item.GroupIndex).FullPath
            End If
        Next
    End If

    Regards,
    Mira
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. D.SRINIVASA
    D.SRINIVASA avatar
    34 posts
    Member since:
    Oct 2010

    Posted 14 Jul 2011 Link to this post

    Hi Mira 
    Thanks for your reply, 
    It works Great..

    Here i have another issue, In my project i have a 2 parent nodes.. ie  AF- Angel Falls and P1 -Phase  when click on Angel Falls Node it selects all the child nodes and displaying data in Grid View. Coming for Header item For 001-Lot1 details header item Display as  AF-Angel Falls shown in Attached file. 1.jpg. here header item should have AF-Angel Falls/P1-Phase1/001-Lot1 for 001-Lot1 details.

    when i click on P1-Phase (Second Parent Node)  it selects all the child nodes and displaying data in Grid View fine. Coming for Header item for 001-Lot1 details
     header item Displays    AF-Angel Falls\P1-Phase1    shown in attach file  2 . jpg. here header item should have AF-Angel Falls/P1-Phase1/001-Lot1 for 001-Lot1 details.


    Please help me.

    Thanks 
    D.Srinivas
  4. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 19 Jul 2011 Link to this post

    Hello D.Srinivasa,

    Please try using the following code on grid pre-render in order to implement the desired functionality:
    Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
        Dim i As Integer = 0
        For Each node As RadTreeNode In RadTreeView1.CheckedNodes
            If node.Level = 2 Then
                Dim headerItem As GridItem = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)(i)
                TryCast(headerItem, GridGroupHeaderItem).DataCell.Text = node.FullPath
                i += 1
            End If
        Next
    End Sub

    I hope it helps.

    Best wishes,
    Mira
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  5. D.SRINIVASA
    D.SRINIVASA avatar
    34 posts
    Member since:
    Oct 2010

    Posted 21 Jul 2011 Link to this post

    Hi Mira 
    Thanks for your reply, 
    It works Great..

    it works perfectly for one single parent nodes only.. when i check the node in one parent child node  ex  : AFAngle Falls and also check the another parent child node ex: RR-Rapid Run   then it fires an error
     " Index was outside the bounds of array "   the following attachment is shown the error.
    Please help me..

    thanks  
    D.Srinivas


  6. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 21 Jul 2011 Link to this post

    Hello D.Srinivasa,

    My code will work only if the count of the groups in the grid is greater than or equal to the count of the checked nodes in the treeview.
    If you have more checked nodes in the treeview than groups in the grid, you can use the following code:
    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs)
        Dim i As Integer = 0
        For Each node As RadTreeNode In RadTreeView1.CheckedNodes
            If node.Level = 2 Then
                If RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader).Length >= i + 1 Then
                    Dim headerItem As GridItem = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)(i)
                    TryCast(headerItem, GridGroupHeaderItem).DataCell.Text = node.FullPath
                    i += 1
                End If
            End If
        Next
    End Sub

    I hope this helps.

    All the best,
    Mira
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  7. D.SRINIVASA
    D.SRINIVASA avatar
    34 posts
    Member since:
    Oct 2010

    Posted 21 Jul 2011 Link to this post

    Hi Mira 
    Thanks for your reply,

    it works greate.....


    Thanks & Regards
    D.Srinivasa
Back to Top