wpfvb.netuser-controlswindowsformshost

Calling a mouse dobleclick on a windowsformhost(wpf) of a usercontrol(winforms)


Im creating a wpf application but i cant seem to work the events of the user control in the mainwindow.axml i create a windowsformhost and i load perfectly the content(load data of a dataset, etc...) when running ,but how can i handle the events of a mouse or keydown i try this.

in the user control:

Public Event DOBLECLICK()
Public Sub sp1_CellDoubleClick(sender As Object, e As 
    FarPoint.Win.Spread.CellClickEventArgs) Handles sp1.CellDoubleClick
    RaiseEvent DOBLECLICK()
End Sub

in the mainwindow: i try to load the event but not seem to respond.

Private Sub WinFormsHost_MouseLeftButtonUp(sender As Object, e As 
    MouseButtonEventArgs) Handles WinFormsHost.MouseLeftButtonUp

    AddHandler host.sp1.CellDoubleClick, AddressOf host.sp1_CellDoubleClick

End Sub


Private Sub Control_MouseDoubleClick_1(sender As Object, e As MouseEventArgs)
    AddHandler host.sp1.CellDoubleClick, AddressOf host.sp1_CellDoubleClick
End Sub

Solution

  • In MainWindow_Loadedfunction, add this:

    AddHandler host.sp1.CellDoubleClick, AddressOf host.sp1_CellDoubleClick
    

    Then create a new function in your class (It gets called when you doubleclick on a cell. Don't use Handles after this because you already added the handler in your MainWindow_Loaded):

    Public Sub sp1_CellDoubleClick(sender As Object, e As FarPoint.Win.Spread.CellClickEventArgs)
        RaiseEvent DOBLECLICK()
    End Sub
    

    Functions WinFormsHost_MouseLeftButtonUp and Control_MouseDoubleClick_1 are not needed. You can remove them.