开发者

wpf : how to handle KeyDown Event for Datagrid?

I have a problem with datagrid control in wpf . when I press enter I want to load selected items in a set of controls, but it seems that datagrid.KeyDown is already handled and it goes to the next item.

I tried using keyup but this event fires when the dat开发者_运维百科agrid keydown had been fired and datagrid goes to the next item.

any idea to handle keydown completely ?


Use the PreviewKeyDown event instead of KeyDown


Maybe KeyDown is handled by a ClassHandler.
Instance listeners come after class listeners.

A good explanation on MSDN.


You can add a comma-separated list of handlers to an event...

Private Sub dgMyDataGrid_KeyDown(sender As Object, e As KeyEventArgs) Handles dgMyDataGrid.KeyDown, dgSymbols.PreviewKeyDown
    
    ' Perform event programming here...    
    
End Sub

This triggers handling of the "preview" event at the same time as the keydown event, so you don't have to write more than one module.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜