Setting ActiveSheetIndex not working

Posted by: ed on 16 July 2019, 5:43 am EST

    • Post Options:
    • Link

    Posted 16 July 2019, 5:43 am EST

    Hi,

    In my application I have a method that adds a new sheet. I am upgrading my application from Spread 9 to Spread 12 (using build 12.45.20181). My existing code from the Spread 9 project is not behaving the same way in Spread 12. Based on Spread 12 help created the following code to try to diagnose what is happening.

    Public Sub AddSchedule()

    Dim shv As New FarPoint.Win.Spread.SheetView()

     With frmMain.spdProj
            .Sheets.Add(shv)
            .ActiveSheet.ActiveColumnIndex = 0
            .ActiveSheet.ActiveRowIndex = 0
            .TabStripPolicy = FarPoint.Win.Spread.TabStripPolicy.Never
            .Sheets.Count = .Sheets.Count + 1
            .ActiveSheetIndex = .Sheets.Count - 1
            .Sheets(0).Visible = False
            .Sheets(.Sheets.Count - 1).Visible = True
            Dim intSheet As Integer = .ActiveSheetIndex
        End With
    
    End Sub
    

    When I call the above Method I have 2 problems;

    1. The sheet added is completely blank.
    2. The ActiveSheetIndex property has a value of -1

    If I save the .xml file and reopen it the new sheet is there. I just seems I can’t access it without saving and reopening.

    Thanks, Ed

  • Posted 16 July 2019, 4:49 pm EST

    Hi Ed,

    I could not observe the issues you mentioned with your given code.

    1. The added sheet has default settings (500 rows and 500 columns)
    2. The ActiveSheetIndex property had a value of 2 (when AddSchedule is invoked for the first time).

    Can you please see the attached sample and see if I’m missing anything else?

    Also, in your code you’re adding two sheets (one with .Sheets.Add() and another with .Sheets.Count = .Sheets.Count + 1). You’re also setting TabStripPolicy to Never so all the previous sheets will no longer be accessible. Is this intended?

    NewSheet_ActiveIndex.zip

    Regards,

    Jitender

  • Posted 17 July 2019, 3:23 am EST

    Hi Jitender,

    Thanks for your help. I was able to run the sample project you sent me without any problem but still having the same problem with my application.

    With regard to your comments;

    1. I set the TabStripPolicy to Never because we don’t use the tab strip to navigate to the different sheets.
    2. I had the code “.Sheets.Count = .Sheets.Count + 1” because of the example in the V12 Help documentation which is as follows:

    Dim fpSpread1 As New FarPoint.Win.Spread.FpSpread()

    Dim shv As New FarPoint.Win.Spread.SheetView()

    fpSpread1.Location = New Point(10, 10)

    fpSpread1.Height = 200

    fpSpread1.Width = 400

    Controls.Add(fpSpread1)

    fpSpread1.Sheets.Add(shv)

    fpSpread1.ActiveSheet.ActiveColumnIndex = 2

    fpSpread1.ActiveSheet.ActiveRowIndex = 2

    fpSpread1.TabStripPolicy = FarPoint.Win.Spread.TabStripPolicy.Always

    fpSpread1.Sheets.Count = 3

    fpSpread1.ActiveSheetIndex = 1

    I eliminated the line of code that sets the sheet count but still having the same problem.

    I don’t know if this is relevant but the only difference I can think of between my code and yours is that .xml file I am using was originally created using a earlier version of Spread. I am able to open the file in my Spread V12 application.

    Ed

  • Posted 18 July 2019, 5:34 pm EST

    Hi,

    Can you please attach your stripped-down application so we can replicate it at our end and investigate the cause of the issue?

    Thanks,

    Jitender

  • Posted 19 July 2019, 4:28 am EST

    Hi Jitender,

    Yes I will try to do that but it will take a couple of days. I want to try something something else on my end first. I will let you know how that works.

    Thanks, Ed

  • Posted 22 July 2019, 2:42 pm EST

    Hi Ed,

    Sure, take your time. We’ll wait until then.

    Regards,

    Jitender

Need extra support?

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

Learn More

Forum Channels