GrapeCity Forums

The GrapeCity Message Boards
Welcome to GrapeCity Forums Sign in | Join | Help
in Search

Add rows problem when using classes

Last post 07-28-2009, 9:30 AM by mikko. 6 replies.
Sort Posts: Previous Next
  •  07-03-2009, 6:55 AM 79816

    Add rows problem when using classes

    I have a web page where I create a spreadsheet. Then I have some classe I use performing different tasks for the sheet. The first class I call:

    Public Function getDataHTMLAndXLSHeader(Optional ByVal forQuestions As String = "", ...Optional ByRef fpS As FarPoint.Web.Spread.FpSpread = Nothing, ...) As String

    Everything is working ok regarding adding new rows and refering to these. Then I call another class to fill the data:

    Public Function getDataHTMLAndXLS(Optional ByVal forQuestions As String = "", ...Optional ByRef fpS As FarPoint.Web.Spread.FpSpread = Nothing.....) As String

    now I can add rows with fpS.Rows.Count = row + answerCount + 1 but I cannot refer to the added rows even though the fpS.Rows.Count shows the right number of rows. I get an index error. I cannot figure out what I'm doing wrong and this behaviour came along when I splitted one class into two. I can add and refer to the new rows anywhere else but in the second class. Any ideas?

  •  07-03-2009, 11:41 AM 79835 in reply to 79816

    Re: Add rows problem when using classes

    Hello,

    I am not sure what you are seeing. Could you post small zipped project reproducing this behavior for us to debug?


    Scott S.
    Product Manager, Spread ASP.NET
    GrapeCity FarPoint
  •  07-27-2009, 8:26 AM 80778 in reply to 79835

    Re: Add rows problem when using classes

    the problem seems to be something else. I do not understand why the following happens (seems like a very simple and straight forward code):

    With fpSpread.Sheets(0)
         .Rows.Count = ViewState("AnswerCount")
          .PageSize = ViewState("AnswerCount")
          .Cells(row, 0, .PageSize - 1, .ColumnCount - 1).CellType = generalDataCell
          .Cells(row, 0, .PageSize - 1, .ColumnCount - 1).HorizontalAlign = HorizontalAlign.Center
    End With

    Immediate window results on the first .cells line:

    ?fpSpread.Sheets(0).Rows.Count
    689
    ?fpSpread.Sheets(0).PageSize
    689
    ?row
    2

    Exception on the first .cells line:

    System.IndexOutOfRangeException: Invalid row index: 2 (must be between -1 and 1).

  •  07-27-2009, 9:33 AM 80780 in reply to 80778

    Re: Add rows problem when using classes

    Hi, 

    I am not able to replicate the issue using your code. The code that you've sent is working fine on my side. Is it possible for you to provide a working sample, that I can run on my computer to replicate this issue?

    Regards, 


    Scott S.
    Product Manager, Spread ASP.NET
    GrapeCity FarPoint
  •  07-28-2009, 5:10 AM 80820 in reply to 80780

    Re: Add rows problem when using classes

    Attachment: tests.zip
    Attached a zipped project. NOTE! the bin folder is missing with the FP components
  •  07-28-2009, 9:09 AM 80829 in reply to 80820

    Re: Add rows problem when using classes

    Hello Mikko, 

    Referring to your sample application, you are getting the exception because in the ibSaveExcel_Click event, you are calling the fpSpread.Dispose() which is removing the fpSpread object. In the ibExcelExportConfirm_Click event when you are setting the .Cells(row, 0, .PageSize - 1, .ColumnCount - 1).CellType = generalDataCell, the fpSpread is not initialized. 

    To resolve the issue, you may either initialize the fpSpread object before calling the .Cells(row, 0, .PageSize - 1, .ColumnCount - 1).CellType = generalDataCell. Or you may comment out the fpSpread.Dispose() statement. 

    Regards, 


    Scott S.
    Product Manager, Spread ASP.NET
    GrapeCity FarPoint
  •  07-28-2009, 9:30 AM 80834 in reply to 80829

    Re: Add rows problem when using classes

    oh sh...t, sorry for taking your time. Never debugged that after restructuring my software. Sorry for taking your time Embarrassed
View as RSS news feed in XML
     FarPoint Forums Home