473,494 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataGrid:Textbox - Enter Key not firing Validate

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

Nov 21 '05 #1
6 3284
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
--------------------------------------------------

Nov 21 '05 #2
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
--------------------------------------------------

Nov 21 '05 #3
Something interesting...the "right arrow" key fires the event...but none of
the other keys do??

-bruce
Nov 21 '05 #4
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" <cb*******@ATrlcarriers.com> wrote in message
news:mn***********************@ATrlcarriers.com...
That override is on the datagrid btw.

Nov 21 '05 #5
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" <cb*******@ATrlcarriers.com> wrote in message
news:mn***********************@ATrlcarriers.com...
That override is on the datagrid btw.

Nov 21 '05 #6
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" <cb*******@ATrlcarriers.com> wrote in message
news:mn***********************@ATrlcarriers.com...
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
--------------------------------------------------

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1481
by: Tetet B via .NET 247 | last post by:
I'm using VB.Net and trying to retrieve the data in the textboxcell of a datagrid after a successful display (used Databind).User can either display data or enter data in the textbox. I canalways get...
1
4035
by: Agnes | last post by:
I need to limit the number of characters in the Textbox column in the datagrid. How can I do that ? Thanks
0
1432
by: awightma | last post by:
Hi, I have a datagrid with a number of textboxes on it. I want one column of my table to be visible=false because it contains the id of the record from the table. For some reason when I set...
3
7261
by: Mike L | last post by:
For a Data Grid in a Win Form, when the user selects a row and then presses the Enter key, how do I capture that the user pressed the enter key?
2
5367
by: Maziar Aflatoun | last post by:
Hi everyone, I have this DataGrid that I bind to a DataTable. However, instead of displaying the column 'Qty', I like to place it in a textbox and display the value of Qty as the default value...
1
2668
by: Irishmaninusa | last post by:
Hello Everyone, I have a datagrid and have used a text box as way to allow a user to edit items in the grid. My question for you is how is it possible to write code for the text change event of...
1
1717
by: jason | last post by:
I've seen a few posts on this issue, but no clear solutions. I have a mulitiline textbox inside a datagrid. I use TemplateColumn to define as multiline with 3 rows. I have other field types...
4
1355
by: Sam | last post by:
Hi, This is driving me totally insane. I have two datagrid controls, and when I click on the first one its Enter event is called properly but the Enter event of the other one is being called...
3
1692
by: kingflux | last post by:
Hello, and thank you in advance for any help you can provide. Each line in our datagrid control contains a product number, description, and a textbox for the user to enter a quantity-to-order. ...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.