Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Trying to cancel key events

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Trying to cancel key events
Link Posted: 13-Jul-2006 03:32
Hi, I am overriding the key methods of Column.  There is no implementation.

However, the key press still goes through and the character shows up in the cell.

Since I am not calling MyBase.xxx, shouldn't just nothing happen as if the user never pressed a key?

Here is the code:

Public Overrides Sub OnKeyDown(ByVal grid As NineRays.Windows.Forms.FlyGrid, ByVal node As NineRays.Windows.Forms.Data.NodeBase, ByVal ke As System.Windows.Forms.KeyEventArgs)

    End Sub

    Public Overrides Sub OnKeyPress(ByVal grid As NineRays.Windows.Forms.FlyGrid, ByVal node As NineRays.Windows.Forms.Data.NodeBase, ByVal ke As System.Windows.Forms.KeyPressEventArgs)

    End Sub
Link Posted: 13-Jul-2006 08:07
Please describe what should you want to do, target or/and context or provide a code sample.
This helps us to estimate situation and give you more exact answer.
Link Posted: 13-Jul-2006 08:31
For example, I am implementing my own version of a multi column dropdown. I am not using the flygrid as the internals of this multi column dropdown that will appear.

In any case, when the user types in a letter, I want to find the first item that matches that letter, and set that as the cell's value.  Maybe nothing will match, so maybe I want to leave it blank.

There may be other things that need to happen instead of what I described, this was just an example.

In any case, I want the keystroke completely ignored.  Since I never called MyBase, I expected this to be the case, to basically allow me to handle the key event completely.
Link Posted: 13-Jul-2006 20:45
Thanks for the info, we'll try to solve this problem to the nearest update.
Link Posted: 13-Jul-2006 23:31
We've fund a way to solve your problem:
To handle KeyDown event in Column you should override
Column.HandleKeyDown method to return true (by default this method return false) and override OnKeyDown method to handle this event.
Also - HierarchyColumn automatically supports 'first letter pressed' search, when column is in ReadOnly mode (or FlyGrid is in ReadOnly mode).
Link Posted: 14-Jul-2006 02:51
It seems like the method never gets called.

For example, I have the following:

Public Overrides Sub OnKeyDown(ByVal grid As NineRays.Windows.Forms.FlyGrid, ByVal node As NineRays.Windows.Forms.Data.NodeBase, ByVal ke As System.Windows.Forms.KeyEventArgs)
        MessageBox.Show(\"hello\")

    End Sub

As I type in a field of this column type, this never runs.

Same goes for OnKeyPress and HandleKeyDown.
Link Posted: 14-Jul-2006 09:02
Can you provide us with a sample to more precisely understand problem and  more operatively provide you with a solution of this problem?
Please send a sample (please zip) to
Link Posted: 18-Jul-2006 02:20
Here is solution of this problem:
[VB.Net]
Public Class TestCol
    Inherits Column
    Sub New(ByVal colName As String)
        MyBase.New(colName)
    End Sub
    Protected Overrides Sub OnEditorSetup(ByVal editor As System.Windows.Forms.TextBox)
        'connect to the editor's events
        AddHandler editor.KeyDown, AddressOf Me.OnEditorKeyDown
    End Sub
    Private Sub OnEditorKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
        MessageBox.Show(\"hello\")
    End Sub
    Public Overrides Function HandleKeyDown(ByVal grid As NineRays.Windows.Forms.FlyGrid, ByVal node As NineRays.Windows.Forms.Data.NodeBase, ByVal ke As System.Windows.Forms.KeyEventArgs) As Boolean
        Return True
    End Function
    
    Public Overrides Sub OnKeyDown(ByVal grid As NineRays.Windows.Forms.FlyGrid, ByVal node As NineRays.Windows.Forms.Data.NodeBase, ByVal ke As System.Windows.Forms.KeyEventArgs)
        MessageBox.Show(\"hello\")
    End Sub    
End Class
Link Posted: 18-Jul-2006 02:33
The problem is that saying:

e.Handled = True

Doesn't do anything.  The letter I typed still appears.

Also, it's not clear why even have OnKeyDown and OnKeyPress overridable events, if there is no point in overriding them?
Link Posted: 18-Jul-2006 10:52
The problem in that this event is fired after processing internal handlers of inplace editor.
May be better to use Editor.TextChanged event to clear contents?
Same search is provided by HierarchyColumn - when user types some character this column tries
to find a cell - may be it will enough to solve your problem?
Also - did you see a 'Context sensitive search...' sample? May be this way of search meets your requirements?

Also, it's not clear why even have OnKeyDown and OnKeyPress overridable events, if there is no point in overriding them?

These notifications are fired when column is in non-edit mode.