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

Unable to get hierarchy (+/-) indicators to disappear with empty rows.

4 Answers 45 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 10 Jun 2011, 11:02 AM

Hello I have created this simple bit of code that displays a hierarchial orders grid (see screen1.jpg)

Now I want to hide the +/- buttons if there are no rows (ie Order Ref 2 & 4) - Having searched the threads and copied the functions from those threads (RadGridView1_ViewCellFormatting,IsExpandable & RadGridView1_ChildViewExpanding)

It just hides them all because rowInfo.ChildRows.Count =0! (as per screen2.jpg)

Can anybody spot where I'm going wrong?


Many thanks

Terry

 

 


Public
Class Form1
  
      
  
      
    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim myOrders = New BindingList(Of Order)()
        Dim myOrderLines = New BindingList(Of OrderLines)()
  
        myOrders.Add(New Order(1, "01/01/2011", "Order for Warehouse"))
        myOrders.Add(New Order(2, "03/05/2011", "Order for home"))
        myOrders.Add(New Order(3, "12/05/2011", "Order ref xyz"))
        myOrders.Add(New Order(4, "16/05/2011", "Order ref abc"))
  
        myOrderLines.Add(New OrderLines(1, "Power Supply"))
        myOrderLines.Add(New OrderLines(1, "Hard Disk"))
        myOrderLines.Add(New OrderLines(3, "Keyboard"))
        myOrderLines.Add(New OrderLines(3, "Mouse"))
  
        RadGridView1.AutoGenerateHierarchy = False
        RadGridView1.AutoGenerateColumns = True
  
        Dim OrderLinesTemplate As New GridViewTemplate
        OrderLinesTemplate.AllowAddNewRow = False
         
  
        OrderLinesTemplate.DataSource = myOrderLines
        'RadGridView1.MasterTemplate.Templates.Add(RolesAndPositionTemplate)
        Me.RadGridView1.MasterTemplate.Templates.Add(OrderLinesTemplate)
  
        'create the relation
        Dim relation As New GridViewRelation(RadGridView1.MasterTemplate)
        relation.RelationName = "Order Lines"
        relation.ParentColumnNames.Add("OrderId")
        relation.ChildColumnNames.Add("OrderLineId")
        relation.ChildTemplate = OrderLinesTemplate
        Me.RadGridView1.Relations.Add(relation)
  
        Me.RadGridView1.DataSource = myOrders
  
  
  
    End Sub
    Private Sub RadGridView1_ViewCellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting
  
        Dim cellX As GridGroupExpanderCellElement = TryCast(e.CellElement, GridGroupExpanderCellElement)
        If cellX IsNot Nothing AndAlso TypeOf e.CellElement.RowElement Is GridDataRowElement Then
  
            If Not IsExpandable(cellX.RowInfo) Then
                cellX.Expander.Visibility = ElementVisibility.Hidden
            Else
                cellX.Expander.Visibility = ElementVisibility.Visible
            End If
        End If
  
  
    End Sub
  
    Private Function IsExpandable(rowInfo As GridViewRowInfo) As Boolean
  
        If rowInfo.ChildRows IsNot Nothing AndAlso rowInfo.ChildRows.Count > 0 Then
            Return True
        Else
            Return False
        End If
  
    End Function
  
    Private Sub RadGridView1_ChildViewExpanding(sender As Object, e As Telerik.WinControls.UI.ChildViewExpandingEventArgs) Handles RadGridView1.ChildViewExpanding
        e.Cancel = Not IsExpandable(e.ParentRow)
    End Sub



4 Answers, 1 is accepted

Sort by
0
Terry
Top achievements
Rank 1
answered on 14 Jun 2011, 10:23 AM
Bump !
Anybody able to help me with this?

Thanks

Terry
0
Martin Vasilev
Telerik team
answered on 15 Jun 2011, 03:28 PM
Hi Terry,

Thank you for writing.

You can use the ViewCellFormatting event to remove the "+" signs for the parents, which do not have any child rows:

void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement is GridGroupExpanderCellElement)
    {
        GridViewDataRowInfo row = e.CellElement.RowInfo as GridViewDataRowInfo;
        GridViewChildRowCollection chRows = row.ChildRows;
        if (chRows.Count == 0)
        {
            e.CellElement.Visibility = ElementVisibility.Hidden;
        }
        else
        {
            e.CellElement.Visibility = ElementVisibility.Visible;
        }
    }
}

If you need a quicker response, you can consider purchasing one of the licenses that we offer. These licenses come with Support packages and the support tickets that one submits from a licensed account are reviewed according to the license that he\she has.

I hope this helps.

Greetings,
Martin Vasilev
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Terry
Top achievements
Rank 1
answered on 21 Jun 2011, 01:32 PM
Hi Martin,

Thanks for the info - At the moment we are evaulating Telerik controls so would not want to commit to a support license until this is complete.

Unfortunately I still cant get your subroutine example to work it just blanks out all the + signs.
I can't attach the project as a zip file - is there any way I can get you to take a look?

Many thanks

Terry
0
Martin Vasilev
Telerik team
answered on 24 Jun 2011, 02:45 PM
Hello Terry,

Please find as attachment a sample project, which demonstrates the approach described above. Write me back if you have any additional questions.

Regards,
Martin Vasilev
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Terry
Top achievements
Rank 1
Answers by
Terry
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or