DataGrid:Textbox - Enter Key not firing Validate

B

Bruce D

I have a datagrid (uggg) that I use and create the columns
programmatically...see below.
objCol = New DataGridTextBoxColumn
objCol.MappingName = "amount"
objCol.HeaderText = "Amount"
objCol.Width = 60
objCol.Format = "C"
objDGTS.GridColumnStyles.Add(objCol)
' create keypress, validating events for this textbox column only
Dim dgtb As DataGridTextBox = CType(objCol.TextBox, DataGridTextBox)
AddHandler dgtb.KeyPress, AddressOf Amount_KeyPress
AddHandler dgtb.Validating, AddressOf Amount_Validating
Everything seems to work great...except that the event "Amount_Validating"
does not fire when I use the "arrow keys" or the "enter key". It fires when
I use the "tab key" or use the mouse to click aournd on the grid. I'm
assuming this has something to do with "focus" or something like that.
Can anyone help me get this event to fire with the enter key/arrow keys?

TIA
-bruce duncan
 
C

Christopher C. Bernholt

Override the IsInputKey method to get arrow keys fire keypress event as
such:

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Up OrElse keyData = Keys.Down OrElse _
keyData = Keys.Right OrElse keyData = Keys.Left OrElse _
keyData = Keys.Enter Then
Return True
End If
End Function

Bruce D expressed precisely :
I have a datagrid (uggg) that I use and create the columns
programmatically...see below.
objCol = New DataGridTextBoxColumn
objCol.MappingName = "amount"
objCol.HeaderText = "Amount"
objCol.Width = 60
objCol.Format = "C"
objDGTS.GridColumnStyles.Add(objCol)
' create keypress, validating events for this textbox column only
Dim dgtb As DataGridTextBox = CType(objCol.TextBox,
DataGridTextBox)
AddHandler dgtb.KeyPress, AddressOf Amount_KeyPress
AddHandler dgtb.Validating, AddressOf Amount_Validating
Everything seems to work great...except that the event "Amount_Validating"
does not fire when I use the "arrow keys" or the "enter key". It fires
when
I use the "tab key" or use the mouse to click aournd on the grid. I'm
assuming this has something to do with "focus" or something like that.
Can anyone help me get this event to fire with the enter key/arrow keys?

TIA
-bruce duncan

--
--------------------------------------------------
Christopher C. Bernholt
I.T. Research & Development
..NET Re-Engineering Team
R & L Carriers, Inc.
http://www.gorlc.com
--------------------------------------------------
 
C

Christopher C. Bernholt

That override is on the datagrid btw.

It happens that Bruce D formulated :
I have a datagrid (uggg) that I use and create the columns
programmatically...see below.
objCol = New DataGridTextBoxColumn
objCol.MappingName = "amount"
objCol.HeaderText = "Amount"
objCol.Width = 60
objCol.Format = "C"
objDGTS.GridColumnStyles.Add(objCol)
' create keypress, validating events for this textbox column only
Dim dgtb As DataGridTextBox = CType(objCol.TextBox, DataGridTextBox)
AddHandler dgtb.KeyPress, AddressOf Amount_KeyPress
AddHandler dgtb.Validating, AddressOf Amount_Validating
Everything seems to work great...except that the event "Amount_Validating"
does not fire when I use the "arrow keys" or the "enter key". It fires when
I use the "tab key" or use the mouse to click aournd on the grid. I'm
assuming this has something to do with "focus" or something like that.
Can anyone help me get this event to fire with the enter key/arrow keys?

TIA
-bruce duncan

--
--------------------------------------------------
Christopher C. Bernholt
I.T. Research & Development
..NET Re-Engineering Team
R & L Carriers, Inc.
http://www.gorlc.com
--------------------------------------------------
 
B

Bruce D

Something interesting...the "right arrow" key fires the event...but none of
the other keys do??

-bruce
 
B

Bruce D

I'm new to VB.NET...
Where do I put the override function? I placed it on the top of my
form...but it didn't work (which I didn't think it would because I don't
understand how tell it to override for th datagrid).

-bruce
 
B

Bruce D

I created a new class (see below) and added it to my project. Now, I'm not
sure how I tell the datagrid on my form to use the new class I created...or
am I way off on what I'm supposed to be doing here in order to get the
override to work?

Public Class dgX
Inherits System.Windows.Forms.DataGrid
Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Up OrElse keyData = Keys.Down OrElse keyData =
Keys.Right OrElse keyData = Keys.Left OrElse keyData = Keys.Enter Then
Return True
End If
End Function
End Class
 
C

Christopher C. Bernholt

You're on the right track. You can override the keydown on the
datagrid now and intercept the arrow keys. Now if you build your new
class, then right click in your tool box and select add/remove then
browse to the dll for your new class, it will add it to the toolbox and
you can use it in your application.

Bruce D :
I created a new class (see below) and added it to my project. Now, I'm not
sure how I tell the datagrid on my form to use the new class I created...or
am I way off on what I'm supposed to be doing here in order to get the
override to work?

Public Class dgX
Inherits System.Windows.Forms.DataGrid
Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Up OrElse keyData = Keys.Down OrElse keyData =
Keys.Right OrElse keyData = Keys.Left OrElse keyData = Keys.Enter Then
Return True
End If
End Function
End Class

--
--------------------------------------------------
Christopher C. Bernholt
I.T. Research & Development
..NET Re-Engineering Team
R & L Carriers, Inc.
http://www.gorlc.com
--------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top