PC Review


Reply
Thread Tools Rate Thread

DataGrid:Textbox - Enter Key not firing Validate

 
 
Bruce D
Guest
Posts: n/a
 
      14th Mar 2005
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



 
Reply With Quote
 
 
 
 
Christopher C. Bernholt
Guest
Posts: n/a
 
      14th Mar 2005
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
--------------------------------------------------

 
Reply With Quote
 
Christopher C. Bernholt
Guest
Posts: n/a
 
      14th Mar 2005
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
--------------------------------------------------

 
Reply With Quote
 
Bruce D
Guest
Posts: n/a
 
      14th Mar 2005
Something interesting...the "right arrow" key fires the event...but none of
the other keys do??

-bruce


 
Reply With Quote
 
Bruce D
Guest
Posts: n/a
 
      14th Mar 2005
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


"Christopher C. Bernholt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> That override is on the datagrid btw.
>



 
Reply With Quote
 
Bruce D
Guest
Posts: n/a
 
      14th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> That override is on the datagrid btw.



 
Reply With Quote
 
Christopher C. Bernholt
Guest
Posts: n/a
 
      14th Mar 2005
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> That override is on the datagrid btw.


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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
one field on a winforms, validate not firing Jeff Jarrell Microsoft VB .NET 3 9th Dec 2006 06:18 PM
Validate the TextBox sureshbabu.sivam@gmail.com Microsoft Outlook Form Programming 0 29th Nov 2005 06:25 AM
Enter Key and Multiline TextBox in DataGrid Art Microsoft Dot NET Framework Forms 0 21st Jun 2005 01:07 PM
HELP! I Lost The Ability To Advance From TextBox To TextBox With the ENTER Or The TAB Keys Minitman Microsoft Excel Programming 0 22nd Feb 2005 08:50 PM
Re: why datagrid's itemcommand event fired when I press ENTER key in a TextBox Natty Gur Microsoft ASP .NET 0 30th Jun 2003 06:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:41 AM.