FlexGrid Property 'Cols' is null

Posted by: c1 on 21 February 2019, 4:20 am EST

    • Post Options:
    • Link

    Posted 21 February 2019, 4:20 am EST

    Hello folks,

    I have a inherited class, based on FlexGrid. Because the user can add/delete/move columns i have serveral times code (VB.NET) like this.

    
    Dim colWork as integer = 0
    while colWork < [b]me.cols[/b].count
    
      ....
    
     colWork += 1
    End While
    
    

    Unfortunabley i get often a null pointer exception and visual Studio points to ‘me.cols’. It seems to me, that the ColumnList ‘cols’ is null in that moment.

    I use (a lot of) try-Statements as a workaround, but I’am wondering about this behavour. What happend here? I expect this property not null all over the time.

    Is there a other (saver) way to get the number of cols/rows (fixed/frozen/total) as my code above?

    Thank in advance for any help.

    Niels

  • Posted 21 February 2019, 6:40 am EST

    Hello folks,

    i am not able to edit my post …

    Perhaps this error fires only on grids which are visible=false (because they are placed on a unvisible tab from a tabcontrol)?

    Niels

  • Posted 22 February 2019, 2:13 am EST

    Hi Niels,

    I used your given code with a custom grid placed on a Tab Page, but I could not observe any NullReferenceException.

    Can you please see the attached sample, and modify it so that we can observe the issue and further investigate it?

    Thanks,

    Jitender

    ColsNullException.zip

  • Posted 22 February 2019, 6:38 am EST

    Hello Jitender,

    thanks for your reply and your sample. There was a real person, looking to my problem :slight_smile: Great service !!!

    I try to modify your sample to force the error - and failed. After this I worked some hours to build a sample with my own flexgrid-class (delete all not relevant code …, simulate the user actions …) and can’t reproduce it into a smaller framework.

    Because this results it must be a problem at my project and not a problem of flexgrid. I found a own mistake by managing userdata into the first gridrow. After solving this, I don’t get the error once more again. Perhaps Visual Studio points to the wrong code position?

    I will test it more detailed. I come back on Monday.

    Once more: Many thanks for looking/reproduce/answering to my problem.

    Have a nice weekend.

    Niels

  • Posted 24 February 2019, 11:51 pm EST

    Hi Niels,

    Thanks for trying out our products.

    That is very unlikely. If you still face any issues after your testing, then please share a stripped-down sample so that we can observe the issue at our end and assist you accordingly.

    Thanks,

    Jitender

  • Posted 28 February 2019, 3:40 am EST

    Hello

    thank you for your post. My problem wasn’t solved, i get still null pointer exeptions.

    I tried to produce a striped down project to reproduce this behaivor - but i can’t.

    • The program crashed (sometimes) after inserting/moving columns if user do one of this actions once more again. It never crashed at the first time doing this.

    • The error was raised into the code of a inherited class from FlexGrid f.e.

     Public Sub emptyData()
        Dim rng As CellRange = GetCellRange(AnzFrozenRows, AnzFrozenCols, Me.Rows.Count - 1, Me.Cols.Count - 1)
        rng.Clear(ClearFlags.All)
    
    End Sub
    
    
    • Visual Studion points to the Cols-property, in this case to ```

      me.cols.count
    
    - The Debugger of Visual Studio explain some suprising results. Some properties of the grid seems to by NULL, other seems to be disposed (but still into memory?) Have a look to the screen-shots.
    
    Do you have any idea about the circumstances that these properties are set to null while running the programm and displaying the grid?
    
    Thanks in advance for any help.
    Niels
    
    [img]https://gccontent.blob.core.windows.net/forum-uploads/file-eea92170-4dfa-4b21-ac27-a05582d1a80d.PNG[/img][img]https://gccontent.blob.core.windows.net/forum-uploads/file-7516c8e6-03ee-4d94-a177-7756c0f40143.PNG[/img]
  • Posted 28 February 2019, 5:28 am EST

    Hi Niels,

    It seems like your control’s Handle is being destroyed prematurely.

    Can you please override OnHandleDestroyed method in your inherited grid, and see if and when this method is invoked.

    You might be able to understand the origin of the issue if you see the StackTrace before this Handle is destroyed.

    If you still can’t resolve this issue, (and cannot produce a replicating sample) then please post your observations, and a video demonstrating the steps you take before this exception is thrown.

    Thanks,

    Jitender

  • Posted 28 February 2019, 7:42 am EST

    Hello Jitender,

    thanks for your feedback.

    I identify, that the error raised only after closing the window (which have the flexgrid) and reopened it. The window is an MDI-Child into the MainForm … perhaps I dispose the Form (and the grid) not propperly?

    I try to modify your given sample to jump into the error, but I failed.

    I build a heavy reduced version of my project (no database, no logging … but it has still a lot of code :-() and have found a way to reproduce the error.

    Is there any possibility to send it directly to you?

    Greatings

    Niels

  • Posted 28 February 2019, 11:15 am EST

    Hello Jitender,

    i found a relationship between the raising the exception and using a C1Ribbon.

    After identify this, it would be easy to modify your given sample to reproduce the error (see attached project)

    To reproduce the error follow these steps:

    1. Click ‘show form’.
    2. Delete one or more columns by using ‘del column’.
    3. Delete one or more columns by using your ‘remove column’ at the form.

    Everything works fine.

    1. Close the form
    2. Open the form again.
    3. Delete a column by using the your ‘remove column’ button.

      This works
    4. Try to delete a columns using ‘del column’ > crashed with the same exception.

    I hope you can reproduce this behavior and could help to fix this.

    Best wishes.

    Niels

    ColsNullException_V2.zip

  • Posted 1 March 2019, 12:39 am EST

    Hi Niels,

    Thanks for the sample. I can observe the behavior with this sample.

    This is what you should do to avoid accessing the Disposed object:

    In your F_MDIForm class, remove the AddHandler from setMenu method:

    Public Sub setMenü(m As K_RibbonMenü, value As Integer)
            Me.m = m
            'AddHandler m.onDelete, AddressOf delete      <= remove this
    End Sub
    

    Override OnHandleCreated and attach the handler for m.onDelete:

    Protected Overrides Sub OnHandleCreated(e As EventArgs)
            MyBase.OnHandleCreated(e)
            AddHandler m.onDelete, AddressOf delete
    End Sub
    

    Override OnHandleDestroyed and detach the handler for m.onDelete:

    Protected Overrides Sub OnHandleDestroyed(e As EventArgs)
            RemoveHandler m.onDelete, AddressOf delete
            MyBase.OnHandleDestroyed(e)
    End Sub
    

    You can refer to the modified sample for these changes.

    Thanks,

    Jitender

    ColsNullException_V2_Modified.zip

  • Posted 1 March 2019, 4:42 am EST

    Hello Jitender,

    GREAT !!!

    Thank you for your help.

    You are right. The added handler (on C1Ribbon) points to a lost form after closing it. I will try a modified version of your solution (using Formclosing Event to remove the handler) because I have some other code at this event.

    Once more: Many thanks for looking/reproduce/answering.

    Thanks a lot.

    Niels

Need extra support?

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

Learn More

Forum Channels