
May 20th, 2012, 01:00 PM
|
|
Contributing User
|
|
Join Date: Aug 2010
Posts: 84
  
Time spent in forums: 20 h 12 m 16 sec
Reputation Power: 4
|
|
|
Condensing this code into a single function?
Hello there Guru's of .Net!
I've got this as a workaround, but I don't think as this is the correct way of doing this; all I am after is getting the "Enter" key to be recognised in a ComboBox, and this is the only way it will work - but even this method has been 'not to reliable'.
Here is the code:-
Code:
'this is called first
Private Sub ParentDescription_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ParentDescription.KeyDown
If e.KeyCode = Keys.Enter Then
AddAssy.Enabled = True
e.Handled = True
Exit Sub
End If
End Sub
'this is a natural second
Private Sub ParentDescription_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ParentDescription.KeyPress
'Check that a keypress is actually enter, and if it is, it's a seperate course of action - set the 'AddSub' button the enabled, then exit :)
'If e.KeyChar = Chr("13") Then
If Asc(e.KeyChar) = Keys.Enter Then
AddAssy.Enabled = True
Exit Sub
End If
'make any aplha char UPPERCASE
If Char.IsLower(e.KeyChar) Then
'Convert to uppercase.
ParentDescription.SelectedText = Char.ToUpper(e.KeyChar)
e.Handled = True
End If
'as you were.
End Sub
Any suggestions on how I could achieve this would be greatly appreciated.
Cheers,
MRb
|