TIA,
Bob
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Me.ComboBox1.Text = ""
Me.ComboBox1.Items.Add("a")
Me.ComboBox1.Items.Add("aaa")
Me.ComboBox1.Items.Add("combo")
Me.ComboBox1.Items.Add("combobox")
Me.ComboBox1.Items.Add("combobox test")
Me.ComboBox1.Items.Add("common")
Me.ComboBox1.Items.Add("common dialog")
End Sub
Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal
e As System.Windows.Forms.KeyEventArgs) Handles
ComboBox1.KeyUp
Dim index As Integer
Dim actual As String
Dim found As String
' Do nothing for some keys such as navigation keys.
If ((e.KeyCode = Keys.Back) Or _
(e.KeyCode = Keys.Left) Or _
(e.KeyCode = Keys.Right) Or _
(e.KeyCode = Keys.Up) Or _
(e.KeyCode = Keys.Delete) Or _
(e.KeyCode = Keys.Down) Or _
(e.KeyCode = Keys.PageUp) Or _
(e.KeyCode = Keys.PageDown) Or _
(e.KeyCode = Keys.Home) Or _
(e.KeyCode = Keys.End)) Then
Return
End If
' Store the actual text that has been typed.
actual = Me.ComboBox1.Text
' Find the first match for the typed value.
index = Me.ComboBox1.FindString(actual)
' Get the text of the first match.
If (index > -1) Then
found = Me.ComboBox1.Items(index).ToString()
' Select this item from the list.
Me.ComboBox1.SelectedIndex = index
' Select the portion of the text that was
automatically
' added so that additional typing will replace
it.
Me.ComboBox1.SelectionStart = actual.Length
Me.ComboBox1.SelectionLength = found.Length
End If
End Sub
>.
>
TIA,
Bob
Option Strict On
Module Main
Private WithEvents frm As Form
Private WithEvents cb As ComboBox
Private WithEvents tx As TextBox
Private scb As SubCombo
Sub main()
frm = New Form()
frm.Show()
cb = New ComboBox()
frm.Controls.Add(cb)
tx = New TextBox()
frm.Controls.Add(tx)
tx.Left = cb.Left + cb.Width + 10
cb.Items.Add("test1")
cb.Items.Add("test2")
cb.Items.Add("test3")
cb.Items.Add("test4")
cb.Items.Add("test5")
scb = New SubCombo()
frm.Controls.Add(scb)
scb.Top = cb.Top + cb.Height + 10
scb.Items.Add("test1")
scb.Items.Add("test2")
scb.Items.Add("test3")
scb.Items.Add("test4")
scb.Items.Add("test5")
Application.Run()
End Sub
Public Sub frm_Closed( _
ByVal sender As Object, ByVal e As System.EventArgs _
) Handles frm.Closed
Application.Exit()
End Sub
Public Class SubCombo
Inherits ComboBox
Protected Overrides Sub OnKeyPress( _
ByVal e As System.Windows.Forms.KeyPressEventArgs _
)
Select Case e.KeyChar
Case Convert.ToChar(Keys.Return)
e.Handled = True
Case Else
MyBase.OnKeyPress(e)
End Select
End Sub
End Class
Public Sub cb_KeyPress( _
ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs _
) Handles cb.KeyPress
Select Case e.KeyChar
Case Convert.ToChar(Keys.Return)
e.Handled = True
End Select
End Sub
Public Sub tx_KeyPress( _
ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs _
) Handles tx.KeyPress
Select Case e.KeyChar
Case Convert.ToChar(Keys.Return)
e.Handled = True
End Select
End Sub
End Module
"Bob" <noe...@nospam.net> wrote in message
news:OsBTbXgdCHA.620@tkmsftngp12...
Something odd is going on here. We are still looking at this, but here is
something you can try short term:
Place an invisible command button on the form and set the AcceptButton
property to that button. When the return key for any controls on the form,
the button will grab it before the control can process it.
HTH,
John Eikanger
Microsoft Visual Basic Developer Support
This posting is provided “AS IS” with no warranties, and confers no rights.
(c) 2002 Microsoft Corporation. All rights reserved.
--------------------
| From: "Bob" <noe...@nospam.net>
| References: <OsBTbXgdCHA.620@tkmsftngp12>
| Subject: Re: looking for example code to make own combo box
| Date: Thu, 17 Oct 2002 14:43:51 -0400
| Lines: 105
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <u8RtnzgdCHA.2408@tkmsftngp11>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 199.2.136.1
| Path: cpmsftngxa06!tkmsftngp01!tkmsftngp11
| Xref: cpmsftngxa06 microsoft.public.dotnet.languages.vb:69746
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
Thanks a lot,
Bob
Option Strict On
Module Main
Private WithEvents frm As Form
Private scb As SubCombo
Sub main()
frm = New Form()
frm.Show()
scb = New SubCombo()
frm.Controls.Add(scb)
scb.Items.Add("test1")
scb.Items.Add("test2")
scb.Items.Add("test3")
scb.Items.Add("test4")
scb.Items.Add("test5")
Application.Run()
End Sub
Public Sub frm_Closed( _
ByVal sender As Object, ByVal e As System.EventArgs _
) Handles frm.Closed
Application.Exit()
End Sub
Public Class SubCombo
Inherits ComboBox
Private WithEvents btn As Button
Private OldAcceptButton As IButtonControl
Private OldCancelButton As IButtonControl
Public Sub New()
btn = New Button()
Me.Controls.Add(btn)
btn.Visible = False
End Sub
Protected Overrides Sub OnKeyPress( _
ByVal e As System.Windows.Forms.KeyPressEventArgs _
)
Select Case e.KeyChar
Case Convert.ToChar(Keys.Return)
e.Handled = True
Case Else
MyBase.OnKeyPress(e)
End Select
End Sub
Protected Overrides Sub OnKeyDown( _
ByVal e As System.Windows.Forms.KeyEventArgs _
)
Select Case e.KeyCode
Case Keys.Return
e.Handled = True
End Select
End Sub
Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
OldAcceptButton = Me.FindForm.AcceptButton
Me.FindForm.AcceptButton = btn
OldCancelButton = Me.FindForm.CancelButton
Me.FindForm.CancelButton = btn
End Sub
Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
Me.FindForm.AcceptButton = OldAcceptButton
Me.FindForm.CancelButton = OldCancelButton
End Sub
End Class
End Module
"John Eikanger [MS]" <joh...@online.microsoft.com> wrote in message
news:eEA3nrjdCHA.2676@cpmsftngxa06...
Here's the way to do it, or as close to right as I'm going to get.
Implement the code in Knowledge Base article Q320583. Here is a link to it:
HOW TO: Trap Keystrokes in .NET Controls by Using Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;[LN];Q320583
I have commented the article to add the keyword "Hook". If, like me, you
like to do things the hard way first, Knowledge Base article Q311317
includes an example of how to hook the WndProc associated with an hWnd and
filter the message before they get to the combo box. The problem with this
approach is that the editable portion of the combobox is a separate window
from the rest of the control. The Handle property of the combobox does not
point that the edit window, so you need to call GetWindow to get the handle
of the editable part of the control.
HTH,
John Eikanger
Microsoft Visual Basic Team
This posting is provided “AS IS” with no warranties, and confers no rights.
(c) 2002 Microsoft Corporation. All rights reserved.
--------------------
| From: "Bob" <noe...@nospam.net>
| References: <OsBTbXgdCHA.620@tkmsftngp12> <u8RtnzgdCHA.2408@tkmsftngp11>
<eEA3nrjdCHA.2676@cpmsftngxa06>
| Subject: Re: looking for example code to make own combo box
| Date: Fri, 18 Oct 2002 10:42:13 -0400
| Lines: 104
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
Protected Overrides Function ProcessCmdKey( _
ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys _
) As Boolean
Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104
If ((msg.Msg = WM_KEYDOWN) _
Or (msg.Msg = WM_SYSKEYDOWN)) Then
Select Case keyData
Case Keys.Enter, Keys.Enter Or Keys.Control, _
Keys.Enter Or Keys.Shift, Keys.Enter Or Keys.Alt
msg = Nothing
End Select
End If
End Function
In one portion of the Knowledge Base article ("Implement the Overridden
Method") I see
Case (Keys.Alt And Keys.Z)
Console.WriteLine("<ALT> + z Captured")
And in a subsequent portion ("Build an Example") I see
Case (Keys.Alt Or Keys.Z)
Me.Parent.Text = "<ALT> + Z Captured"
'OR' seems to work, but not 'AND'. Perhaps I found a mistake?
Thanks very much for your help!
Bob
"John Eikanger [MS]" <joh...@online.microsoft.com> wrote in message
news:8wFNkfvdCHA.2280@cpmsftngxa08...
Good catch. It should be OR all around. I have logged the content change
request.
Thanks,
John Eikanger
Microsoft Visual Basic Team
This posting is provided “AS IS” with no warranties, and confers no rights.
(c) 2002 Microsoft Corporation. All rights reserved.
--------------------
| From: "Bob" <noe...@nospam.net>
| Subject: Re: looking for example code to make own combo box
| Date: Sat, 19 Oct 2002 14:17:27 -0400
| Lines: 70
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb