ExpandRow method does not cause ChildViewCreate event

Posted by: shetal11 on 8 September 2017, 12:42 pm EST

  • Posted 8 September 2017, 12:42 pm EST

    Hi,


    I have spread with multiple levels of child view. When I click on '+' sign next to parent to expand row it causes ChildViewCreate event where i set one of the column of childview to be type checkbox. On my form I also have a button to expand selected row, which should behave same way as user has clicked on '+' sign. On that button click event I am calling ExpandRow method. This ExpandRow method does not call ChildViewCreate event. I also have tried to create seprate method which will setup one of the column of ChildView to type checkbox. This method gets called on button click event and on childviewcreate event. It works fine when called from ChildViewCreate event but does not work when called from my button click event.


     


    Any help would be appriciated.


    Thanks


    Shetal

  • Replied 8 September 2017, 12:42 pm EST

    Hello,


    Calling the ExpandRow method causes the ChildViewCreated event to be called. So your SetupChild function is being called twice. Thus there is not a need to call the SetupChild function in the Button_Click event after expanding the row. This should keep the Spread from painting this twice.


    I do not understand the second problem you are seeing. Could you post a small zipped project reproducing this issue for us to debug?

  • Replied 8 September 2017, 12:42 pm EST

    Shetal,


    When calling the ExpandRow method, the child sheet is not attached to the child SpreadView, so layout changes is not able to be made. You can change your code in the SetupChild function to get the checkboxes to show on column 1.

     
      Private Sub SetupChild(ByVal sv As FarPoint.Win.Spread.SheetView)
    FpSpread1.Refresh()
    sv.Columns(1).CellType = New FarPoint.Win.Spread.CellType.CheckBoxCellType
    End Sub
     
  • Replied 8 September 2017, 12:42 pm EST

    Shetal,


    Once the child SheetView is created, then the ChildViewCreated event will not be called. If you are using the GetChildView method in your code, this will create the child SheetView. Then, if you call the ExpandRow after that, then the sheet is already created and the event will not fire. Also, make sure you have the latest maintenance release of the product.

  • Replied 8 September 2017, 12:42 pm EST

    Hi Scott,


    Doing Spread.Refresh seems to work fine. But, now there is some delay in refresh screen. On my form I have it setup to expand all the rows initially. Now each time it expands one row it goes through the chilviewcreate and does FPSpread1.Refresh. Visually I can see each row expanding being blank than getting refresh with checkbox and othere stuff that i do in SetupChild method. Also initally all my parent row is hidden undernith first child row and than when I expand form little bit or resize my form, all the parent and child row are visible.


     


     

  • Replied 8 September 2017, 12:42 pm EST

    Hi Scott,


    I tried on a small project and it does not seem to be a problem with ChildViewCreate event.


    Private Sub FpSpread1_ChildViewCreated(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.ChildViewCreatedEventArgs) Handles FpSpread1.ChildViewCreated


             SetupChild(e.SheetView)


    End Sub


    Private Sub SetupChild(ByVal sv As FarPoint.Win.Spread.SheetView)


          sv.Columns(1).CellType = New FarPoint.Win.Spread.CellType.CheckBoxCellType


    End Sub


    I have a button on my form. OnClick event should expand the selected row.


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


          FpSpread1.ActiveSheet.ExpandRow(0, True)


          SetupChild(FpSpread1.ActiveSheet.GetChildView(0, 0))


    End Sub


     


    Now click event and ChildView create event both calls same Method 'SetupChild'. I don't get the check box column when called from button Click event, but I do get it when called from ChildViewCreate event.


     


    Thanks


    Shetal


     

  • Replied 8 September 2017, 12:42 pm EST

    Thanks Scott,


    That seems to work fine. I am also using part of code that was posted on another thread to expand all the rows initially.


    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenNodes(FpSpread1.Sheets(0))
      End Sub

      Private Sub
    OpenNodes(ByVal ss As FarPoint.Win.Spread.SheetView)
        Dim ss2 As FarPoint.Win.Spread.SheetView
        For i As Integer = 0 To ss.RowCount - 1
          If ss.ChildRelationCount > 0 Then
            ss2 = ss.GetChildView(i, 0)
            ss.ExpandRow(i, True)
            OpenNodes(ss2)
          End If
        Next
      End Sub


    This piece of code also has some problem that all the children does not go through my SetupChild method. Is there a way to use SpreadView in this OpenNodes method insted of SheetView?


     

  • Replied 8 September 2017, 12:42 pm EST

    Shetal,


    Let us make a couple of changes to this code and then it will work. The way it is now, the child SheetView object is not being associated with any SpreadView objects and thus the ChildViewCreated event is not firing when calling the ExpandRow method on it. There is another ExpandRow method on the SpreadView object that will make things work as you expect. First change the m_ActiveSView object to be a SpreadView object and not a SheetView object and then make the following changes.

     
      Private Sub FpSpread1_CellClick(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs) Handles FpSpread1.CellClick
    m_ActiveSView = e.View
    m_ActiveRow = e.Row
    End Sub

    Private Sub
    Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If m_ActiveSView Is Nothing Then
    Exit Sub
    End If

    If
    m_ActiveSView.Sheets(0).ChildRelationCount > 0 Then
    m_ActiveSView.ExpandRow(m_ActiveRow, True)
    End If
    End Sub
     
  • Replied 8 September 2017, 12:42 pm EST

    Shetal,


    Are you trying to open all child sheets at once? If so, it may be the Sheets ar enot being attached to the Spread control, so the Spread does not know the sheets are being opened. You would need to cause the child sheet to be 'attached' to the Spread control. You can do something like calling the Refresh method on the Spread control after opening each sheet.


    If this is not the cause, I would need to have some project to debug the issue to tell yuo what may be happening. Also, make sure you get the latest maintenance relesase (2.5.2011).

  • Replied 8 September 2017, 12:42 pm EST

    Soctt,


    Attached please find 3 images.


    1step.gif : This is the behavior I am seeing when initially all the rows are being expanded. Each parent has next row hidden.


    2step.gif : Once I resize my form this what I get. I am looking for something like this to comeup initially not with the gaps like 1step.gif.


    3step.gif : The ExpandRow method calls ChildViewCreate event for parent row. In my case I can have upto 5 levels. So when I click on expand button(calls Expand Row method)  to expand one of the childern, CildViewCreate event does not get fire and I get something like this image. That is the resone I am calling SetupChild method in ChildViewCreate event and in ExpandButton Click event.


    I hope this images help you understand the problem more..


    Thanks


    Shetal..


    2007/07/images.zip
  • Replied 8 September 2017, 12:42 pm EST

    Shetal,


    What release of Spread for Windows Forms are you using? Make sure you have the latest maintenance release. I am not able to reproduce the issues you are seeing with the rows not opening correctly. Could you post a small zipped project reproducing this problem for us to debug?

  • Replied 8 September 2017, 12:42 pm EST

    Scoot,


    I am using 2.5.2009.2005. It is hard for me to have small project. I tried myself and could not reproduce in the sample project. Anyways, I have found workaround for that. After SetupChild is called I am doing GetPreferedWidth and that seems to refix the screen.


     


    My last issue with this Thread..


    Can you find out why ChildViewCreate event does not happen when children row is Expanded using ExpandRow Method?


    For Example:

    - 1 Parent Row
          - 2 Children Row
                3 GrandChildren Row


    When row 1 is expaned using ExpandRow method. ChildViewCreate event happens. But when Row 2 is expanded using ExpandRow method ChildViewCreate event does not happen for Row 3.


    Thanks


    Shetal


     


     

  • Replied 8 September 2017, 12:42 pm EST

    Scott,


     


    I am in process of downloading the 2.5.2011. Meanwhile, attached please find project to debug for u. This is one of the sample project which came with product. I have changed it little bit. It has button on the page. on click event of that page it expands selected row. If you put the breakpoint on ChildViewCreate event, and select the first row and click on the button. It will go on the event. Now, if you select the child row of first row and hit the button again, it will not go to the ChildViewCreate event.


    Thanks


    Shetal..


    2007/07/HierarchyVB.zip
  • Replied 8 September 2017, 12:42 pm EST

    Shetal,


    I changed that line of code again and now it seems to open all levels down.

     
    ss2 = ss.GetSpreadView(ss.Sheets(0)GetChildView(i, 0),0,0)
     
  • Replied 8 September 2017, 12:42 pm EST

    Thanks Soctt,


    It seems to work fine now.. Thanks for your great quick help...

  • Replied 8 September 2017, 12:42 pm EST

    Shetal,


    I did not update the code completely. It should reas as follows.

     
    ss2 = FpSpread1.GetRootWorkBook.GetSpreadView(ss.Sheets(0)GetChildView(i, 0),0,0)


     
  • Replied 8 September 2017, 12:42 pm EST

    Scott,


    ss2 = FpSpread1.GetRootWorkBook.GetSpreadView(ss.GetChildView(i, 0),0,0)


    ss does not have GetChildView method..


    Thanks


    Shetal

  • Replied 8 September 2017, 12:42 pm EST

    Scott,


    While waiting for your reply friday, I already tried that, and it seemed to work but not completely. It expands the parent row and first children.


    After that
    ss2 = FpSpread1.GetRootWorkBook.GetSpreadView(ss.Sheets(0)GetChildView(i, 0),0,0)
    returns 'nothing'.


    so, it does not expand all the levels down.


    Thanks


    Shetal..

  • Replied 8 September 2017, 12:42 pm EST

    Hello,


    Here you go.

     
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    OpenNodes(FpSpread1.GetRootWorkbook)
    End Sub

    Private Sub
    OpenNodes(ByVal ss As FarPoint.Win.Spread.SpreadView)
    Dim ss2 As FarPoint.Win.Spread.SpreadView
    For i As Integer = 0 To ss.Sheets(0).RowCount - 1
    If ss.Sheets(0).ChildRelationCount > 0 Then
    ss.ExpandRow(i, True)
    ss2 = FpSpread1.GetRootWorkBook.GetSpreadView(ss.GetChildView(i, 0),0,0)
    OpenNodes(ss2)
    End If
    Next
    End Sub


     
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels