473,986 Members | 44,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event Handler for Control Key F2

hello to all, I found in Internet the following code that is very usefull to me. The code detects any character that is entered to datagrid, I am interested in the control key F2 but I don't know how to adding an event handler to a column of datagrid that raise when this key is pressed. Please help m

Private Sub AddCustomDataTa bleStyle(
Dim ts1 As New DataGridTableSt yle(
ts1.MappingName = "Customers
' Add textbox column style so we can catch textbox mouse click
Dim TextCol As New DataGridKeyTrap TextBoxColum
TextCol.Mapping Name = "custID
TextCol.HeaderT ext = "CustomerID
TextCol.Width = 10
ts1.GridColumnS tyles.Add(TextC ol

''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''add handler (help)''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''

DataGridKeyTrap TextBoxColumn._ RowCount = myDataSet.Table s("Customers"). Rows.Coun
ts1.GridColumnS tyles.Add(TextC ol
dataGrid1.Table Styles.Add(ts1
End Sub 'AddCustomDataT ableStyl

Public Class DataGridKeyTrap TextBoxColum
Inherits DataGridTextBox Colum
Private _keyTrapTextBox As KeyTrapTextBox = Nothin
Private _source As System.Windows. Forms.CurrencyM anager = Nothin
Private _rowNum As Intege
Private _isEditing As Boolean = Fals
Public Shared _RowCount As Integer =

Public Sub New(
_keyTrapTextBox = New KeyTrapTextBo
_keyTrapTextBox .BorderStyle = BorderStyle.Non

AddHandler _keyTrapTextBox .Leave, AddressOf LeaveKeyTrapTex tBo
AddHandler _keyTrapTextBox .KeyPress, AddressOf TextBoxEditStar te
End Sub 'Ne

Private Sub TextBoxEditStar ted(ByVal sender As Object, ByVal e As KeyPressEventAr gs
_isEditing = Tru
MyBase.ColumnSt artedEditing(CT ype(sender, Control)
End Sub 'TextBoxEditSta rte

Private Sub LeaveKeyTrapTex tBox(ByVal sender As Object, ByVal e As EventArgs
If _isEditing The
SetColumnValueA tRow(_source, _rowNum, _keyTrapTextBox .Text
_isEditing = Fals
Invalidate(
End I
_keyTrapTextBox .Hide(
End Sub 'LeaveKeyTrapTe xtBo

Protected Overloads Overrides Sub Edit(ByVal [source] As System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean

_RowCount = [source].Coun

MyBase.Edit([source], rowNum, bounds, [readOnly], instantText, cellIsVisible

_rowNum = rowNu
_source = [source

_keyTrapTextBox .Parent = Me.TextBox.Pare n
_keyTrapTextBox .Location = Me.TextBox.Loca tio
_keyTrapTextBox .Size = Me.TextBox.Siz
_keyTrapTextBox .Text = Me.TextBox.Tex
Me.TextBox.Visi ble = Fals
_keyTrapTextBox .Visible = Tru
_keyTrapTextBox .BringToFront(
_keyTrapTextBox .Focus(
End Sub 'Edi

Protected Overrides Function Commit(ByVal dataSource As System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer) As Boolea
If _isEditing The
_isEditing = Fals
SetColumnValueA tRow(dataSource , rowNum, _keyTrapTextBox .Text
End I
Return Tru
End Function 'Commi
End Class 'DataGridKeyTra pTextBoxColum

Public Class KeyTrapTextBo
Inherits TextBo

Public Sub New(
End Sub 'Ne

Private Const WM_KEYDOWN As Integer = &H10
Private Const WM_KEYUP As Integer = &H10
Private Const WM_CHAR As Integer = &H10

Public Overrides Function PreProcessMessa ge(ByRef msg As Message) As Boolea
Dim keyCode As Keys = CType(msg.WPara m.ToInt32(), Keys) And Keys.KeyCod
If msg.Msg = WM_KEYDOWN The
Console.WriteLi ne(("TextBox.WM _KEYDOWN key: " + keyCode.ToStrin g())
End I

' for a datagrid, we need to eat the tab key oe else its done twic
If msg.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Tab The
'to ignore a message return true without calling baseclas
'to let the textbox handle message return false;
'don't let textbox handle tab
Return True
End If
Return MyBase.PreProce ssMessage(msg)

' //sample handling code. This lets the textbox handle the delete
' //& preventing (for example) a delete shortcut on a menu getting it
' if((msg.Msg == WM_KEYDOWN)
' && keyCode == Keys.Delete)
' {
' //to ignore a message return true without calling baseclass
' //to let the textbox handle message return false;
'
' //let textbox handle Delete
' return false;
' }
'Return MyBase.PreProce ssMessage(msg)
End Function 'PreProcessMess age
End Class 'KeyTrapTextBox
Nov 20 '05 #1
3 2304
Hi,

http://www.syncfusion.com/FAQ/WinFor...c44c.asp#q836q

Ken
---------------
"Carmen de Lara" <cd*****@diario .com.mx> wrote in message
news:E3******** *************** ***********@mic rosoft.com...
hello to all, I found in Internet the following code that is very usefull
to me. The code detects any character that is entered to datagrid, I am
interested in the control key F2 but I don't know how to adding an event
handler to a column of datagrid that raise when this key is pressed.
Please help me

Private Sub AddCustomDataTa bleStyle()
Dim ts1 As New DataGridTableSt yle()
ts1.MappingName = "Customers"
' Add textbox column style so we can catch textbox mouse
clicks
Dim TextCol As New DataGridKeyTrap TextBoxColumn
TextCol.Mapping Name = "custID"
TextCol.HeaderT ext = "CustomerID "
TextCol.Width = 100
ts1.GridColumnS tyles.Add(TextC ol)
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''add
handler
(help)''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' '''''''''''''

DataGridKeyTrap TextBoxColumn._ RowCount =
myDataSet.Table s("Customers"). Rows.Count
ts1.GridColumnS tyles.Add(TextC ol)
dataGrid1.Table Styles.Add(ts1)
End Sub 'AddCustomDataT ableStyle

Public Class DataGridKeyTrap TextBoxColumn
Inherits DataGridTextBox Column
Private _keyTrapTextBox As KeyTrapTextBox = Nothing
Private _source As System.Windows. Forms.CurrencyM anager = Nothing
Private _rowNum As Integer
Private _isEditing As Boolean = False
Public Shared _RowCount As Integer = 0

Public Sub New()
_keyTrapTextBox = New KeyTrapTextBox
_keyTrapTextBox .BorderStyle = BorderStyle.Non e

AddHandler _keyTrapTextBox .Leave, AddressOf LeaveKeyTrapTex tBox
AddHandler _keyTrapTextBox .KeyPress, AddressOf TextBoxEditStar ted
End Sub 'New

Private Sub TextBoxEditStar ted(ByVal sender As Object, ByVal e As
KeyPressEventAr gs)
_isEditing = True
MyBase.ColumnSt artedEditing(CT ype(sender, Control))
End Sub 'TextBoxEditSta rted

Private Sub LeaveKeyTrapTex tBox(ByVal sender As Object, ByVal e As
EventArgs)
If _isEditing Then
SetColumnValueA tRow(_source, _rowNum, _keyTrapTextBox .Text)
_isEditing = False
Invalidate()
End If
_keyTrapTextBox .Hide()
End Sub 'LeaveKeyTrapTe xtBox

Protected Overloads Overrides Sub Edit(ByVal [source] As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal
bounds As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal
instantText As String, ByVal cellIsVisible As Boolean)

_RowCount = [source].Count

MyBase.Edit([source], rowNum, bounds, [readOnly], instantText,
cellIsVisible)

_rowNum = rowNum
_source = [source]

_keyTrapTextBox .Parent = Me.TextBox.Pare nt
_keyTrapTextBox .Location = Me.TextBox.Loca tion
_keyTrapTextBox .Size = Me.TextBox.Size
_keyTrapTextBox .Text = Me.TextBox.Text
Me.TextBox.Visi ble = False
_keyTrapTextBox .Visible = True
_keyTrapTextBox .BringToFront()
_keyTrapTextBox .Focus()
End Sub 'Edit

Protected Overrides Function Commit(ByVal dataSource As
System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer) As Boolean
If _isEditing Then
_isEditing = False
SetColumnValueA tRow(dataSource , rowNum, _keyTrapTextBox .Text)
End If
Return True
End Function 'Commit
End Class 'DataGridKeyTra pTextBoxColumn

Public Class KeyTrapTextBox
Inherits TextBox

Public Sub New()
End Sub 'New

Private Const WM_KEYDOWN As Integer = &H100
Private Const WM_KEYUP As Integer = &H101
Private Const WM_CHAR As Integer = &H102

Public Overrides Function PreProcessMessa ge(ByRef msg As Message) As
Boolean
Dim keyCode As Keys = CType(msg.WPara m.ToInt32(), Keys) And
Keys.KeyCode
If msg.Msg = WM_KEYDOWN Then
Console.WriteLi ne(("TextBox.WM _KEYDOWN key: " +
keyCode.ToStrin g()))
End If

' for a datagrid, we need to eat the tab key oe else its done twice
If msg.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Tab Then
'to ignore a message return true without calling baseclass
'to let the textbox handle message return false;
'don't let textbox handle tab
Return True
End If
Return MyBase.PreProce ssMessage(msg)

' //sample handling code. This lets the textbox handle the delete
' //& preventing (for example) a delete shortcut on a menu getting
it
' if((msg.Msg == WM_KEYDOWN)
' && keyCode == Keys.Delete)
' {
' //to ignore a message return true without calling baseclass
' //to let the textbox handle message return false;
'
' //let textbox handle Delete
' return false;
' }
'Return MyBase.PreProce ssMessage(msg)
End Function 'PreProcessMess age
End Class 'KeyTrapTextBox

Nov 20 '05 #2
i saw the code but i don't know how to raise an event handler to trap de F2 key control and then show a new form. Please help me

Nov 20 '05 #3
Hi,

Here is some code. It pops us a messagebox when you press f2.
You could just as easily open a form or raise an event.

Public Class KeyTrapTextBox
Inherits TextBox

Public Sub New()
End Sub 'New
Private Const WM_KEYDOWN As Integer = &H100
Private Const WM_KEYUP As Integer = &H101
Private Const WM_CHAR As Integer = &H102
Public Overrides Function PreProcessMessa ge(ByRef msg As Message) As
Boolean
Dim keyCode As Keys = CType(msg.WPara m.ToInt32(), Keys) And
Keys.KeyCode
If msg.Msg = WM_KEYDOWN Then
Console.WriteLi ne(("TextBox.WM _KEYDOWN key: " +
keyCode.ToStrin g()))
End If

' for a datagrid, we need to eat the tab key oe else its done twice
If msg.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Tab Then
'to ignore a message return true without calling baseclass
'to let the textbox handle message return false;
'don't let textbox handle tab
Return True
ElseIf msg.Msg = WM_KEYDOWN AndAlso keyCode = Keys.F2 Then
MessageBox.Show ("F2")
End If
Return MyBase.PreProce ssMessage(msg)

' //sample handling code. This lets the textbox handle the delete
' //& preventing (for example) a delete shortcut on a menu getting
it
' if((msg.Msg == WM_KEYDOWN)
' && keyCode == Keys.Delete)
' {
' //to ignore a message return true without calling baseclass
' //to let the textbox handle message return false;
'
' //let textbox handle Delete
' return false;
' }
'Return MyBase.PreProce ssMessage(msg)
End Function 'PreProcessMess age
End Class 'KeyTrapTextBox

Ken
------------------------
"Carmen de Lara" <cd*****@diario .com.mx> wrote in message
news:C9******** *************** ***********@mic rosoft.com...
i saw the code but i don't know how to raise an event handler to trap de F2
key control and then show a new form. Please help me.

Nov 20 '05 #4

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

Similar topics

8
7958
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the same control. Is there anyone who has tried this before and knows why this is hapenning ??
18
2912
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
6
1883
by: vbMark | last post by:
If I have a control, for example a CheckedListBox, how do I add and event to code, for example that a box has been checked by the user? Thanks
1
11628
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
12
4171
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. However in vb.net you get continual messages (even setting the system modal property). Firstly, are these two assumptions right and if so what is the approved
41
4377
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
0
2970
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it such as when they do a delete. Everything is great. By and large it will be used in my repeater controls using the command event when the user clicks on it and so that event is working great. My issue is the Click event. When the control is...
4
9713
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person writing the JavaScript doesn't have to pass the index in the "onChange" event name. I thought that one might be able to use "this.value" or compare this as
1
5267
by: David Veeneman | last post by:
I am writing a control that relies on its host to validate the contents of one of its fields. The control fires a custom 'FooNeedsValidating' event and passes the field's data with the event. The host handles the event, validates the data and returns the validation results to the control by a callback to a control method, SetFooError(). All of that works great. If the host returns false on the validation, I display an error glyph next to...
9
2484
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the post event will always execuate after the system is completed... - I want to wrap this functionality in a framework, so I could possibly have 3 or 4 levels of inherited objects that need to have these pre / post events executed before and after the...
0
10384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11645
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10116
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7654
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6448
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6602
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5200
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3797
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.