Home Forums WinForms controls Xceed Grid for WinForms DoubleClick in a cell throws TargetInvocationException

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13311 |

    Hello,

    First I want to thank you for a wonderful and versatile component for different uses. It has given us a possibility to focus our core knowledge rather than working with the standard grid features.

    Anyway, I have encountered a problem with the development work. We have a grid with certain unbounded DataRows. I should handle a double click in a certain Cell. Thanks for your good documentation, I’ve done the basic subscribe method with following code:

    Dim cl As Xceed.Grid.Cell

    For Each cl In Me.gridVartil.DataRowTemplate.Cells
    AddHandler cl.DoubleClick, AddressOf gridcell_DblClick
    Next

    I’ve defined the gridcell_DblClick like this:

    Private Sub gridcell_DblClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim dCell As Xceed.Grid.DataCell
    Dim dTag As String
    dCell = CType(sender, Xceed.Grid.DataCell)
    dTag = dCell.Tag.ToString
    Debug.Write dTag
    End Sub

    For some reason, this throws me the TargetInvocationException. If I comment out the last three lines, no error is given.

    Any ideas?

    Thank you,
    Ville Mattila

    Imported from legacy forums. Posted by vmattila (had 2900 views)

    User (Old forums)
    Member
    Post count: 23064

    Maybe dCell.Tag doesn’t have a value yet (Null value)? If dCell.Tag is Null then dCell.Tag.ToString will throw an exception. First check if it isn’t null.

    Imported from legacy forums. Posted by Tommy (had 238 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello,

    Thanks for your answer Tommy. I have not been familiar with TargetInvocationException and I didn’t understood that it’s just an error that is caused due another error in a subscribed event. For my opinion, this should have been handled in a little bit better way in VB.NET. It takes some time to debug the code to find out the reason of the error. In fact, running the program not in the debug mode gives a better view on stacks.

    Ville

    Imported from legacy forums. Posted by vmattila (had 304 views)

    User (Old forums)
    Member
    Post count: 23064

    To see the exact error: put the code in a Try..Catch(Exception ex) block, and in the Catch block, display the exception, with MsgBox ex.ToString()
    You can also set a breakpoint on that line, and in the debugger you can check your variables.

    Imported from legacy forums. Posted by Tommy (had 3974 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.