Spread inside another FpSpread cell

Posted by: berry on 8 September 2017, 1:30 pm EST

  • Posted 8 September 2017, 1:30 pm EST

    Hi,


    I want to have a spread placed inside a cell of another spread that i have. I referred to the solution in  http://www.clubfarpoint.com/Forums/forums/thread/11514.aspx


    I was able to see the cell with my custom spread cell type. However when scrolling I see that the new spread scrolls along instead of sticking to its cell.


    I'm using FpSpread for .net framework 3.5


    Please do suggest ways to avoid this.


     Regards,


    Berry

  • Replied 8 September 2017, 1:30 pm EST

    Berry -

    You would have to use the code in the post you referenced when scrolling the spread.  The custom celltype code is only painting a spread on top of the cell.  You could use the GetEditorControl method to return a spread for when you go into edit mode or you can take a look at the SpreadChildControls sample that ships with the product.

  • Replied 8 September 2017, 1:30 pm EST

    Bob,


    I'm not too sure about what you were saying.


    Is it this way?


    Problem: The child spread remains always visible in the parent spread when scrolling


    Referenced code does not solve the above problem


    Work Around 1: Use GetEditorControl method


    Work Around 2: Place child controls


    Bob,


    About method 1, could throw more light, as I dont understand how it can be used to solve the problem


    About method 2, I had the same problem 


    Please confirm the above and suggest other methods if any, or please explain the above better


    Thanks


    Berry 


     

  • Replied 8 September 2017, 1:30 pm EST

     Problem: The child spread remains always visible in the parent spread when scrolling

     

    The code Scott provided is spot on and keeps the spread from scrolling and works perfectly in my test.

     

    Private Sub FpSpread1_LeftChange(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.LeftChangeEventArgs) Handles FpSpread1.LeftChange
    If e.NewLeft > 1 Then
    s.Visible = False
    End If
    End Sub


    Private Sub FpSpread1_TopChange(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.TopChangeEventArgs) Handles FpSpread1.TopChange
    If e.NewTop > 1 Then
    s.Visible = False
    End If
    End Sub

  • Replied 8 September 2017, 1:30 pm EST

    Oops! I missed it.


    Works like a charm.


    Thanks to you Bob and Scott too


     


    Regards,


    Berry

  • Replied 8 September 2017, 1:30 pm EST

    Berry,


    I would like to point out Bob's first woraround as a better solution to this functionality. In my original code, I was creating a Spread control over the cell location and making sure it scrolled with the Spread. There are a lot of possibilities for problems with this code. In the later versions of Spread, there is now a DrawToBitmap method to paint a spreadsheet. You can use this to paint a cell when it is not in editmode and then when the user goes into editmode, override the GetEditorControl to create a Spread control and in the SetEditorValue override, load the settings for the Spread.


    Public Class mySpread


    Inherits FarPoint.Win.Spread.CellType.EditBaseCellType


    Dim ss As FarPoint.Win.Spread.FpSpread


    Dim sz As Size


    Public Sub New()


    ss = New FarPoint.Win.Spread.FpSpread


    ss.Sheets.Count = 1


    End Sub


    Public Overrides Sub PaintCell(ByVal g As System.Drawing.Graphics, ByVal r As System.Drawing.Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal isSelected As Boolean, ByVal isLocked As Boolean, ByVal zoomFactor As Single)


    Dim b As New Bitmap(r.Width, r.Height)


    sz = New Size(r.Width, r.Height)


    ss.Size = sz


    ss.DrawToBitmap(b, New Rectangle(0, 0, r.Width, r.Height))


    g.DrawImage(b, r.X, r.Y)


    End Sub


    Public Overrides Function GetEditorValue() As Object


    Dim ms As New System.IO.MemoryStream


    ss.Save(ms, False)


    ms.Position = 0


    Return ms


    End Function


    Public Overrides Sub SetEditorValue(ByVal value As Object)


    Dim ms As System.IO.MemoryStream


    If Not value Is Nothing Then


    ms = CType(value, System.IO.MemoryStream)


    ss.Open(ms)


    Else


    ss.Sheets.Count = 1


    End If


    End Sub


    Public Overrides Function GetEditorControl(ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal zoomFactor As Single) As System.Windows.Forms.Control


    ss.Reset()


    Return ss


    End Function


    End Class

Need extra support?

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

Learn More

Forum Channels