abraXus
  • abraXus
  • Advanced Member Topic Starter
2021-06-18T03:05:40Z
The IGPrintManager gives me an error: An item with the same key has already been added.

It does not error when building the preview, but instead gives the error once the preview form opens, and the user clicks the Print button that it part of that form.

I have narrowed it down to setting the SpanCols property for the first cell equal to the Cols.Count (and the grid has more than one column)

Below is the code that can reproduce it. Please let me know if I am doing something wrong or if the IGPrintManager needs to be fixed.

Imports TenTec.Windows.iGridLib

Public Class Form3
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With IGrid1
            With .Cols
                .Add("Category", "Category")
                .Add("Sub-Category", "Sub-Category")
            End With
            For i As Integer = 0 To 5
                Dim newRow As iGRow = .Rows.Add()
                newRow.Cells("Category").Value = "cat " & i
                newRow.Cells("Category").SpanCols = .Cols.Count ' REMOVING THIS LINE FIXES IT
                'newRow.Cells("Category").SpanCols = .Cols.Count -1 ' REPLACING THE ABOVE LINE WITH THIS LINE ALSO FIXES IT, BUT THEN THE CELLS DO NOT SPAN THE ENTIRE GRID
            Next
        End With
    End Sub

    Private Sub PrintButton_Click(sender As Object, e As EventArgs) Handles PrintButton.Click
        IGPrintManager1.Grid = IGrid1
        IGPrintManager1.PageFooter.RightSection.Text = Now.ToString("MMMM d, yyyy")
        IGPrintManager1.Document.DefaultPageSettings.Margins = New System.Drawing.Printing.Margins(25, 25, 25, 25) ' 1/100 of an inch
        IGPrintManager1.FitColsOnPage = Printing.iGFitColsOnPage.ScaleGrid
        IGPrintManager1.PrintPreview() ' error happens here
    End Sub
End Class
Igor/10Tec
2021-06-18T14:26:45Z
I can run it successfully with the latest release (v10.0.24).

Are you using the latest version? If not, download and install the latest demo that includes iGrid v10.0.24. Then try to reproduce the problem with it.
abraXus
  • abraXus
  • Advanced Member Topic Starter
2021-06-19T00:34:52Z
Yes, I am using iGrid.NET 10.0.24.0

if it helps, the PrintManager is also 10.0.24.0 and it says Runtime Version v4.0.30319

UserPostedImage

Again, it does not happen until the preview form opens and then the print button is clicked. It works just fine up until that point.

I do not have any control over what happens after it opens the preview, as that is handled by the PrintManager. The preview appears to be fine. It does not error when first executing the line in question, it errors AFTER that when the user clicks the print button. Are you clicking the print button? Are you using an actual printer? Does paper come out of the printer?
Igor/10Tec
2021-06-19T05:48:27Z
The comment 'error happens here' after the PrintPreview() call confused me. Yes, indeed, the problem occurs when I click the Print button in the Print Preview dialog.

Give us some time to investigate this problem and provide the fixed version of PrintManager for testing. We'll continue this process in email correspondence not to bloat this thread. I will post here again when we have a robust solution.
Igor/10Tec
2021-06-23T10:27:39Z
I sorted out this problem. Actually it occurred when we tried to print iGrid with merged cells AFTER doing print-preview. The problem didn't occur if we sent such a grid directly to the printer.

An email with the link to the fixed version of PrintManager has been just sent to you.
abraXus
  • abraXus
  • Advanced Member Topic Starter
2021-06-24T00:12:34Z
That does fix the problem outlined above, however, now I am getting a different error when there are 2 grids using same IGPrintManager. I seem to have narrowed it down to the 2 grids having a different number of columns.

This time the error happens before the preview displays.

System.ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values.'

Below is the code to demonstrate it.

To get the error:
1. Click PrintButton and it will preview the first grid. (no errors)
2. Click PrintButton2 and it will give you the error.

If you click PrintButton2 first, it will work, and then if you click PrintButton (the first one) it will work too, but then when you then click the PrintButton2 again, you get the error then as well.

Was it not designed to be used like this?

I hope that makes sense. If you have trouble duplicating it, please let me know.

    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With IGrid1
            With .Cols
                .Add("Category", "Category")
                .Add("Sub-Category", "Sub-Category")
                .Add("Description", "Description") ' everything works if you remove this line
            End With
            For i As Integer = 0 To 5
                Dim newRow As iGRow = .Rows.Add()
                newRow.Cells("Category").Value = "cat " & i
                newRow.Cells("Category").SpanCols = .Cols.Count
            Next
        End With

        With IGrid2
            With .Cols
                .Add("Category", "Category")
                .Add("Sub-Category", "Sub-Category")
            End With
            For i As Integer = 0 To 5
                Dim newRow As iGRow = .Rows.Add()
                newRow.Cells("Category").Value = "cat " & i
                newRow.Cells("Category").SpanCols = .Cols.Count
            Next
        End With

    End Sub

    Private Sub PrintButton_Click(sender As Object, e As EventArgs) Handles PrintButton.Click
        IGPrintManager1.Grid = IGrid1
        IGPrintManager1.PrintPreview()
    End Sub

    Private Sub PrintButton2_Click(sender As Object, e As EventArgs) Handles PrintButton2.Click
        IGPrintManager1.Grid = IGrid2
        IGPrintManager1.PrintPreview()
    End Sub
Igor/10Tec
2021-06-24T11:51:18Z
I investigated this new issue. It is not related to the previous bug fix. The problem occurs in the current official build too if you switch from one iGrid to another in the same instance of PrintManager.

Give me enough time to analyze all code paths and provide a robust solution allowing us to switch between grids this way. If you need an urgent workaround, use two different instances of PrintManager to print/print-preview two different grids.
abraXus
  • abraXus
  • Advanced Member Topic Starter
2021-06-25T02:46:14Z
The work around I used in the meantime is just to remove the IGPrintManager component, then add Import TenTec.Windows.iGridLib.Printing and then declare it when I need it.

    Private Sub PrintButton_Click(sender As Object, e As EventArgs) Handles PrintButton.Click
        Dim IGPrintManager1 As New iGPrintManager
        IGPrintManager1.Grid = IGrid1
        IGPrintManager1.PrintPreview()
    End Sub

    Private Sub PrintButton2_Click(sender As Object, e As EventArgs) Handles PrintButton2.Click
        Dim IGPrintManager1 As New iGPrintManager
        IGPrintManager1.Grid = IGrid2
        IGPrintManager1.PrintPreview()
    End Sub

This will be "good enough" for me, even tho it would still be ideal to have it work the way I had it.

Igor/10Tec
2021-06-25T08:22:42Z
A link to the latest interim build of PrintManager that should fix this problem was sent to you. Don't hurry with posting your feedback and test it thoroughly with various grids.