Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8695

Re: PB 12.5.1 .Net - How to stop arrow keys from scrolling datawindow row?

$
0
0

It's a bit more complicated than that.  In later versions of Windows controls (WinForms and WPF), Microsoft decided that certain keys on the keyboard (including the arrow keys) would no longer fire a KeyDown event.  That is, unless the PreviewKeyDown event was overridden to set the IsInput value to true.

 

What you're going to need to do to implement this is to implement some event delegation.

 

1.  Create a new event on the datawindow called PreviewKeyDown that takes and argument of System.Object called sender and an argument of System.Windows.RoutedEventArgs called e.

 

2.  In the open event of the window (or the constructor event of the datawindow) assign the event you created above as the delegate for the PreviewKeyDownEvent for the datawindow control. For example, if your datawindow was called dw_1, you would have code like the following:

 

System.Windows.RoutedEventHandler reh
System.Windows.RoutedEvent re
reh = dw_1.PreviewKeyDown
re = System.Windows.Input.Keyboard.PreviewKeyDownEvent
dw_1.InnerControl.AddHandler ( re, reh )

 

3.  At this point you can add code to your new event to respond to the arrow keys.  You might check to see what key was pressed and if it was an arrow key then simple indicate that the event has been handled.

 

e.handled = true

 

The PreviewKeyDown and KeyDown event are paired events, so telling the previewkeydown event it's been handled halts the processing at that point.  The datawindow will no longer scroll.

 

Alternatively, you could set the IsInput attribute in the PreviewKeyDown so that the arrow keys fire the KeyDown event, and then add the code that does the arrow key handling to the regular KeyDown event.

 

I often tell people that "you can do anything with PowerBuilder given enough time and money".  With that in mind, when somebody tells you that "It can't be done with PowerBuilder" what you might want to interpret that to mean instead is that "I don't know how to do that with PowerBuilder."


Viewing all articles
Browse latest Browse all 8695

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>