Question

Im trying to host a Datagridview in a WPF usercontrol. The datagridview is added to the winformshost in the constructor and the Enter and Leave events wired up. The Enter event fires the first time the grid gets focus but not subsequently and the leave event is never fired.

Any ideas? Thanks

Was it helpful?

Solution

MSDN says:

Enter and Leave events are not raised when the following focus changes occur:

  • From inside to outside a WindowsFormsHost control.

  • From outside to inside a WindowsFormsHost control.

  • Outside a WindowsFormsHost control.

  • From a Windows Forms control hosted in a WindowsFormsHost control to an ElementHost control hosted inside the same WindowsFormsHost.

So if you want the leave and enter events to fire you'd have to leave to another control in the same WindowsFormsHost. This would only be possible by creating a usercontrol containing the datagridview and another control.

Feels like a hack though. If you can, just live with the fact that it's not supported.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top