|
-
Jul 28th, 2007, 03:18 PM
#1
Thread Starter
New Member
How do I make the Enter Key behave like the Tab key in a combobox in VB 2005?
Hi all,
Can anyone help with this?
I've searched for suggestions in previous postings but what I found doesn't seem to work for me...
Thanks in advance for your help!
-
Jul 28th, 2007, 04:39 PM
#2
Re: How do I make the Enter Key behave like the Tab key in a combobox in VB 2005?
Modify the arguments to suit your needs...
Code:
Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
If e.KeyCode = Keys.Return Then
SelectNextControl(ComboBox1, True, False, False, True)
End If
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 29th, 2007, 03:28 AM
#3
Thread Starter
New Member
Re: How do I make the Enter Key behave like the Tab key in a combobox in VB 2005?
Thanks, but unfortunately it doesn't seem to work
Any other suggestions?
-
Jul 29th, 2007, 03:46 AM
#4
Re: How do I make the Enter Key behave like the Tab key in a combobox in VB 2005?
Did you read up on the arguments for it? This is why I mentioned for you to modify it for your needs. 
Does your combo box have the name "ComboBox1"? Do you have the forms KeyPreview property set to True?
The code works for me.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 29th, 2007, 04:09 AM
#5
Thread Starter
New Member
Re: How do I make the Enter Key behave like the Tab key in a combobox in VB 2005?
yep, I did all the changes you mentioned but it still doesn't seem to work
Perhaps there's something missing? I just want the user to be able to press Enter instead of Tab and get the info related to the selected item in the ComboBox (this info is output in a RichTextBox). Here is the code I'm experimenting with (the programme is a sort of dictionary which is meant to show in the RichTextBox the selected item in the ComboBox - which is a Middle English word - its pronunciation and its translation into Modern English).
Any help greatly appreciated!
Code:
Imports Microsoft.Office.Interop
Imports System.IO
Public Class Form1
Dim k As Integer = 1000
Dim objExcel As Excel.Application
Dim data As Excel.Range
Dim i As Integer = 1
Private Sub OpenExcel()
objExcel = New Excel.Application
End Sub
Private Sub CloseExcel()
objExcel.Workbooks.Close()
objExcel.Quit()
objExcel = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim sheet As New Excel.Worksheet
Dim row As Integer
OpenExcel()
sheet = objExcel.Workbooks.Open _
("C:\Documents and Settings\Cristiano\Documenti\1_Canterbuty_Tales").Worksheets.Item(1)
objExcel.Range("A2:H" & k).Select()
data = objExcel.Selection
For row = 2 To k
cmbEntries.Items.Add(Data(row, 4).value)
Next
End Sub
Private Sub cmbEntries_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmbEntries.SelectedIndexChanged
rtbTrans.Clear()
Dim boldFont As New Font("Arial", 12, FontStyle.Bold)
Dim noBold As New Font("Arial", 8, FontStyle.Regular)
Dim transFont As New Font("Ipa-samd Uclphon1 SILDoulosL", 10, FontStyle.Italic)
rtbTrans.SelectionFont() = boldFont
rtbTrans.AppendText(data(cmbEntries.SelectedIndex + 2, 4).text)
rtbTrans.AppendText(vbCrLf)
rtbTrans.SelectionFont() = transFont
rtbTrans.AppendText(data(cmbEntries.SelectedIndex + 2, 6).text)
rtbTrans.AppendText(vbCrLf)
rtbTrans.SelectionFont() = noBold
rtbTrans.AppendText(data(cmbEntries.SelectedIndex + 2, 8).text)
rtbTrans.AppendText(vbCrLf)
End Sub
Private Sub cmbEntries_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles cmbEntries.KeyDown
If e.KeyCode = Keys.Enter Then
SelectNextControl(cmbEntries, True, False, False, True)
End If
End Sub
End Class
-
Jul 29th, 2007, 04:56 AM
#6
Re: How do I make the Enter Key behave like the Tab key in a combobox in VB 2005?
Did you set the forms KeyPreview property to True like I mentioned? Is your rich textbox control the next in the tab index order? Is the RTB in a groupbox or panel etc?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 29th, 2007, 05:16 AM
#7
Thread Starter
New Member
Re: How do I make the Enter Key behave like the Tab key in a combobox in VB 2005?
yep, I set the KeyPreview property to True and the RTB is the next in the TabIndex order. Both the ComboBox and the RichTextBox are directly on the form (I haven't used a GroupBox).
Btw, I also tried:
If e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
End If
but it doesn't do the trick either.
-
Jul 29th, 2007, 05:20 AM
#8
Re: How do I make the Enter Key behave like the Tab key in a combobox in VB 2005?
Place a breakpoint on the If statement and then run your app. When you press a key down it should fire the event but not go into the if block. Press enter and it should step into the if block and activate the next control. Sendkeys wont work unless the form is focused and active
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 29th, 2007, 08:55 AM
#9
Thread Starter
New Member
Re: How do I make the Enter Key behave like the Tab key in a combobox in VB 2005?
I think I've found what causes the problem. It's the AutoCompleteMode for the ComboBox, which I have set to Append. If it is set to None, the Enter key works the same as the Tab key. But I can't understand how I can have it both ways (i.e. Append + Enter working as in the None mode)...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|