Hi,
I have 3 questions regarding the code below:
1) Why can't I trap the KEYDOWN while I can trap KEYUP?
2) Is it correct that I use Return True within the IF-Statement? (I've
already read the documentation but it is rather hard to understand so please
don't refer to it :)
3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as
the last code line while I have used Return MyBase.ProcessKeyEventArgs(m)
according to the MSDN, is this correct or is it a typo in MSDN? (watch for
line breaks in the url)
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformscontrolclasspr
ocesskeypreviewtopic.htm
I aslo wonder if my code is correct as to subtitude Enter key with Tab in a
specifik column of the a datagrid. It seems to function well when trapping
the WM_KEYUP but to get the desired effect I need
to trap the WM_KEYDOWN, and doesn't work!
Protected Overrides Function ProcessKeyPreview(ByRef m As
System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And Keys.KeyCode
Const WM_KEYDOWN As Integer = &H100
Const WM_KEYUP As Integer = &H101
If m.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _
AndAlso DataGridColumnStyle1.TextBox Is ActiveControl _
AndAlso DataGrid1.DataSource.GetType Is GetType(DataView) Then
SendKeys.Send("{Tab}")
Return True
End If
Return MyBase.ProcessKeyEventArgs(m)
End Function
--
Thanks in advance
Ali Eghtebas Sweden 3 4075
> 1) Why can't I trap the KEYDOWN while I can trap KEYUP?
??? Whats happening when you try to trap keydown? 2) Is it correct that I use Return True within the IF-Statement? (I've already read the documentation but it is rather hard to understand so
please don't refer to it :)
The return value is dependant on what the function does. If you process the
key return true, if you don't, return false.
3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m)
as the last code line while I have used Return MyBase.ProcessKeyEventArgs(m) according to the MSDN, is this correct or is it a typo in MSDN? (watch for line breaks in the url)
I can't see where ProcessKeyEventArgs appears anywhere, but it's wrong
anyway. It should be:
Return MyBase.ProcessKeyPreview(m)
This is because you are overriding the function, and so you are now letting
the original function process the key. The original function, that you
overrode, is not called, because you have overridden it, so calling that
line will call the original function and return the value that the original
function would have done.
(I hope that make sense)
Also, just FYI, Theres a better way to select the next control in a form,
other than sending the 'Tab' key (if you've seen my post about simulating
keystrokes earlier you'll realise I think it's bad). If you look at the
Me.SelectNextControl method, you can select the next control, based on the
ActiveControl:
Me.SelectNextControl(Me.ActiveControl, True)
More information on this:
<WatchForWrapping>
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformscontrolclassse
lectnextcontroltopic.htm
</WatchForWrapping>
--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)
" There's no place like 127.0.0.1 "
Please respond to the newsgroup,
so all can benefit.
One Day,
"Ali Eghtebas" <al***@home.se> wrote in message
news:eO**************@tk2msftngp13.phx.gbl... Hi,
I have 3 questions regarding the code below:
1) Why can't I trap the KEYDOWN while I can trap KEYUP? 2) Is it correct that I use Return True within the IF-Statement? (I've already read the documentation but it is rather hard to understand so
please don't refer to it :) 3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m)
as the last code line while I have used Return MyBase.ProcessKeyEventArgs(m) according to the MSDN, is this correct or is it a typo in MSDN? (watch for line breaks in the url)
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformscontrolclasspr ocesskeypreviewtopic.htm
I aslo wonder if my code is correct as to subtitude Enter key with Tab in
a specifik column of the a datagrid. It seems to function well when trapping the WM_KEYUP but to get the desired effect I need to trap the WM_KEYDOWN, and doesn't work!
Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And
Keys.KeyCode Const WM_KEYDOWN As Integer = &H100 Const WM_KEYUP As Integer = &H101
If m.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _ AndAlso DataGridColumnStyle1.TextBox Is ActiveControl _ AndAlso DataGrid1.DataSource.GetType Is GetType(DataView) Then SendKeys.Send("{Tab}") Return True End If Return MyBase.ProcessKeyEventArgs(m) End Function
-- Thanks in advance Ali Eghtebas Sweden
The issue was solved by overriding ProcessCmdKey instead ;)
This might be an issue in .Net Framework 1.1.
--
Regards
Ali Eghtebas Sweden
"Ali Eghtebas" <al***@home.se> wrote in message
news:e6**************@TK2MSFTNGP10.phx.gbl... 1) Why can't I trap the KEYDOWN while I can trap KEYUP? ??? Whats happening when you try to trap keydown?
Actually what happens is that nothing happens since the execution never
gets into the If-Statement where I want to replace the Enter key with Tab key. NOTE that I use .Net Framework 1.1. This must be a bug or something since according to the documentation I should be able to trap both KEYDOWN and KEYUP, which seems to only apply
on KEYUP in this case. To be more specifik m.Msg = WM_KEYUP returns True while m.Msg = WM_KEYDOWN returns FALSE!
3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as the last code line while I have used Return MyBase.ProcessKeyEventArgs(m) according to the MSDN, is this correct or is it a typo in MSDN? (watch for line breaks in the url) I can't see where ProcessKeyEventArgs appears anywhere, but it's wrong anyway. It should be:
Return MyBase.ProcessKeyPreview(m)
This is because you are overriding the function, and so you are now letting the original function process the key. The original function, that you overrode, is not called, because you have overridden it, so calling that line will call the original function and return the value that the original function would have done.
(I hope that make sense)
This makes sence to me and that is also what I thought but the only confusing thing about it is MSDN: "Notes to Inheritors: When overriding the ProcessKeyPreview method in a derived class, a control should return true to indicate that it has processed the key. For keys that are not processed by the control, the result of calling the base class's ProcessKeyEventArgs method should be returned."
Also, just FYI, Theres a better way to select the next control in a
form, other than sending the 'Tab' key (if you've seen my post about
simulating keystrokes earlier you'll realise I think it's bad). If you look at the Me.SelectNextControl method, you can select the next control, based on
the ActiveControl:
Me.SelectNextControl(Me.ActiveControl, True)
More information on this: <WatchForWrapping>
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformscontrolclassse lectnextcontroltopic.htm </WatchForWrapping>
The reason I want to replace the Enter Key with Tab is not that I want
give the focus to the next control on my form. I do this since in the last row
in a DataGrid when editing a Cell the Enter Key doesn't assign the new value
to the Cell since this is the last row and hence there is no next row to move the focus on. I simply send Replace the Enter with Tab there to make the change in the Cell and trigger other code within CurrentCellChanged.
One Day, "Ali Eghtebas" <al***@home.se> wrote in message news:eO**************@tk2msftngp13.phx.gbl... Hi,
I have 3 questions regarding the code below:
1) Why can't I trap the KEYDOWN while I can trap KEYUP? 2) Is it correct that I use Return True within the IF-Statement? (I've already read the documentation but it is rather hard to understand so please don't refer to it :) 3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as the last code line while I have used Return MyBase.ProcessKeyEventArgs(m) according to the MSDN, is this correct or is it a typo in MSDN? (watch for line breaks in the url)
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformscontrolclasspr ocesskeypreviewtopic.htm
I aslo wonder if my code is correct as to subtitude Enter key with Tab in a specifik column of the a datagrid. It seems to function well when trapping the WM_KEYUP but to get the desired effect I need to trap the WM_KEYDOWN, and doesn't work!
Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And Keys.KeyCode Const WM_KEYDOWN As Integer = &H100 Const WM_KEYUP As Integer = &H101
If m.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _ AndAlso DataGridColumnStyle1.TextBox Is ActiveControl _ AndAlso DataGrid1.DataSource.GetType Is GetType(DataView) Then SendKeys.Send("{Tab}") Return True End If Return MyBase.ProcessKeyEventArgs(m) End Function
-- Thanks in advance Ali Eghtebas Sweden
Glad you've got it sorted!! "Notes to Inheritors: When overriding the ProcessKeyPreview method in a derived class, a control should return true to indicate that it has processed the key. For keys that are not processed by the control, the result of calling the base class's ProcessKeyEventArgs method should be returned."
Technically this is correct, though I see why you might find it confusing.
It's all about how the new events in VB are delegate methods. It simply
means call the base class' version of the method to make sure it gets
notified of the message.
--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)
" There's no place like 127.0.0.1 "
Please respond to the newsgroup,
so all can benefit.
One Day,
"Ali Eghtebas" <al***@home.se> wrote in message
news:#m**************@TK2MSFTNGP12.phx.gbl... The issue was solved by overriding ProcessCmdKey instead ;) This might be an issue in .Net Framework 1.1. -- Regards Ali Eghtebas Sweden
"Ali Eghtebas" <al***@home.se> wrote in message news:e6**************@TK2MSFTNGP10.phx.gbl... > 1) Why can't I trap the KEYDOWN while I can trap KEYUP? ??? Whats happening when you try to trap keydown? Actually what happens is that nothing happens since the execution never gets into the If-Statement where I want to replace the Enter key with Tab
key. NOTE that I use .Net Framework 1.1. This must be a bug or something since according to the documentation I should be able to trap both KEYDOWN and KEYUP, which seems to only apply on KEYUP in this case. To be more specifik m.Msg = WM_KEYUP returns True while m.Msg =
WM_KEYDOWN returns FALSE!
> 3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as > the last code line while I have used Return MyBase.ProcessKeyEventArgs(m) > according to the MSDN, is this correct or is it a typo in MSDN?
(watch for > line breaks in the url)
I can't see where ProcessKeyEventArgs appears anywhere, but it's wrong anyway. It should be:
Return MyBase.ProcessKeyPreview(m)
This is because you are overriding the function, and so you are now letting the original function process the key. The original function, that you overrode, is not called, because you have overridden it, so calling
that line will call the original function and return the value that the original function would have done.
(I hope that make sense)
This makes sence to me and that is also what I thought but the only confusing thing about it is MSDN: "Notes to Inheritors: When overriding the ProcessKeyPreview method in a derived class, a control should return true to indicate that it has processed the key. For keys that are not processed by the control, the result of calling the base class's ProcessKeyEventArgs method should be returned."
Also, just FYI, Theres a better way to select the next control in a
form, other than sending the 'Tab' key (if you've seen my post about simulating keystrokes earlier you'll realise I think it's bad). If you look at
the Me.SelectNextControl method, you can select the next control, based on the ActiveControl:
Me.SelectNextControl(Me.ActiveControl, True)
More information on this: <WatchForWrapping>
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformscontrolclassse lectnextcontroltopic.htm </WatchForWrapping>
The reason I want to replace the Enter Key with Tab is not that I want
give the focus to the next control on my form. I do this since in the last
row in a DataGrid when editing a Cell the Enter Key doesn't assign the new
value to the Cell since this is the last row and hence there is no next row to
move the focus on. I simply send Replace the Enter with Tab there to make the change in the Cell and trigger other code within CurrentCellChanged.
One Day, "Ali Eghtebas" <al***@home.se> wrote in message news:eO**************@tk2msftngp13.phx.gbl... > Hi, > > I have 3 questions regarding the code below: > > 1) Why can't I trap the KEYDOWN while I can trap KEYUP? > 2) Is it correct that I use Return True within the IF-Statement?
(I've > already read the documentation but it is rather hard to understand
so please > don't refer to it :) > 3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as > the last code line while I have used Return MyBase.ProcessKeyEventArgs(m) > according to the MSDN, is this correct or is it a typo in MSDN?
(watch for > line breaks in the url) > >
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformscontrolclasspr > ocesskeypreviewtopic.htm > > I aslo wonder if my code is correct as to subtitude Enter key with
Tab in a > specifik column of the a datagrid. It seems to function well when trapping > the WM_KEYUP but to get the desired effect I need > to trap the WM_KEYDOWN, and doesn't work! > > Protected Overrides Function ProcessKeyPreview(ByRef m As > System.Windows.Forms.Message) As Boolean > Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And Keys.KeyCode > Const WM_KEYDOWN As Integer = &H100 > Const WM_KEYUP As Integer = &H101 > > If m.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _ > AndAlso DataGridColumnStyle1.TextBox Is ActiveControl _ > AndAlso DataGrid1.DataSource.GetType Is GetType(DataView)
Then > SendKeys.Send("{Tab}") > Return True > End If > Return MyBase.ProcessKeyEventArgs(m) > End Function > > -- > Thanks in advance > Ali Eghtebas Sweden
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ali Eghtebas |
last post by:
Hi,
I have 3 questions regarding the code below:
1) Why can't I trap the KEYDOWN while I can trap KEYUP?
2) Is it correct that I use Return True within the IF-Statement? (I've
already read...
|
by: Susanne Christe |
last post by:
Hi Folks,
I'm trying to override protected ProcessCmdKey function in writing my a
custom MyDataGrid.
I get the Keys I want, but it takes no effect to MyDataGrid, if I try
for example execute...
|
by: Diogo Alves - Software Developer |
last post by:
I'm tring to override the combination all the combination like this one Ctrl
+ Shift + . I just can't catch it... I have already done this
for ctrl + or Shift + but for both at same
timeI can't...
|
by: Niks |
last post by:
I have a list control. On doubleclick of list item, a new dlg opens. Now, i want to handle 'OnEnter Key'also. i.e. When a list item is selected & Enter key is pressed, the new dlg shd open
I tried...
|
by: jibran |
last post by:
Hello. I have wrapped the DataGrid control with my own class (SmartDataGrid)
adding some necessary functionality. My current webform has 2
SmartDataGrids. The first is populated by selected...
|
by: Melson |
last post by:
hi
can anyone help me how can i capture ENTER keystroke when the cell in
datagrid is in editing mode.
I'm now creating a data entry form with primary key in header and details in
datagrid. So...
|
by: zacks |
last post by:
Is there any way to distinguish the keypad Enter key from the standard
Return key?
|
by: Raj |
last post by:
Windows application C#: I have a datagrid, in the 2nd column the user has to
press the enter key between the contents and once entered the data from the
cursor point till end should move to next...
|
by: Peted |
last post by:
Hello,
i am lookinf for the best way to trap any alphanumeric keypress in all
multi key combminations and execute some code
For example , i have a form visible using the form.showdialog...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| | |