How to SetFocus to a ComboBox? |
Post Reply |
Author | |
Jebo
Senior Member Joined: 27 October 2005 Location: Germany Status: Offline Points: 318 |
Post Options
Thanks(0)
Posted: 08 February 2011 at 3:35pm |
Hello!
What I wanted to do is to set the cursor inside a ComboBox to enable write text. I was trying many thinks like that: Dim Combo As CommandBarComboBox Set Combo = MinBar.Controls.Find(xtpControlComboBox, 123) Combo.SetFocus ...but it doesn't work. So please, how to SetFocus to a ComboBox and allow to start edit? |
|
[Sig removed by Admin: Signature can't exceed 40GB]
|
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
Looks like the ComboBox isn't properly forwarding the focus to the edit window of the control (notice if you start typing, it works but misses the first character that you typed).
It looks like using the SetFocus API on the edit handle works though:
|
|
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3 Language: Visual Basic 6.0 SP6 |
|
Jebo
Senior Member Joined: 27 October 2005 Location: Germany Status: Offline Points: 318 |
Post Options
Thanks(0)
|
Thanks, but I had tested already with SetFocus-API. But it doesn't work! BTW: I use an commandBar-ContextMenu AND a MiniBar. The ComboBox is a part of the MiniBar!!! |
|
[Sig removed by Admin: Signature can't exceed 40GB]
|
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
I didn't try it with the Minibar - maybe that's the problem? I will see if I can find a workaround and get back to you.
|
|
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3 Language: Visual Basic 6.0 SP6 |
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
This appears to work okay, but you lose the fade in of the MiniToolbar:
|
|
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3 Language: Visual Basic 6.0 SP6 |
|
Jebo
Senior Member Joined: 27 October 2005 Location: Germany Status: Offline Points: 318 |
Post Options
Thanks(0)
|
Thank you, but it still not work with Mini-Toolbars!
Here is my complete code. So you can see it doesn't work! Option Explicit Public oCmdBar As CommandBar Private Declare Function apiSetFocus Lib "user32.dll" Alias "SetFocus" (ByVal hwnd As Long) As Long Private Declare Function apiGetFocus Lib "user32.dll" Alias "GetFocus" () As Long Private mo_MiniToolbar As XtremeCommandBars.MiniToolBar Private mo_Combo As XtremeCommandBars.CommandBarComboBox Private Sub Command1_Click() mo_MiniToolbar.PopupContextMenu oCmdBar End Sub Private Sub CommandBars1_Update(ByVal Control As XtremeCommandBars.ICommandBarControl) If Control Is mo_Combo Then If Control.Visible Then If apiGetFocus <> mo_Combo.EditHandle Then Debug.Print "Setting Focus " & Timer apiSetFocus mo_Combo.EditHandle End If End If End If End Sub Private Sub Form_Load() With CommandBars1 Set oCmdBar = .ContextMenus.Add(1, "Test1") .ContextMenus.AddPopup mo_MiniToolbar Set mo_MiniToolbar = .AddMiniToolBar("Test2") With mo_MiniToolbar Set mo_Combo = .Controls.Add(xtpControlComboBox, 100, "Test") With mo_Combo .DropDownListStyle = True End With End With End With oCmdBar.Controls.Add xtpControlButton, 1, "Test1" End Sub |
|
[Sig removed by Admin: Signature can't exceed 40GB]
|
|
jpbro
Senior Member Joined: 12 January 2007 Status: Offline Points: 1355 |
Post Options
Thanks(0)
|
I think the problem is that the oCmdBar part of the popup is eating the keyboard presses to see if it should execute one of the menu items. In your example, if you type T it will exexute the Test1 control. Any other keypress will do nothing (since there are no matching captions to execute.
What exactly do you need to accomplish? You want a ComboBox with focus, and a menu beneath it that doesn't accept accelerator key presses (that is, all keypresses go to the combobox, but the menu below remains visible)? If so, you will probably have to open a support ticket for this. |
|
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3 Language: Visual Basic 6.0 SP6 |
|
Jebo
Senior Member Joined: 27 October 2005 Location: Germany Status: Offline Points: 318 |
Post Options
Thanks(0)
|
> If so, you will probably have to open a support ticket for this.
Yes, already done now... Hope, they can help me. |
|
[Sig removed by Admin: Signature can't exceed 40GB]
|
|
Jebo
Senior Member Joined: 27 October 2005 Location: Germany Status: Offline Points: 318 |
Post Options
Thanks(0)
|
I have tried to open a second MiniToolbar without a part of a popup. But now I have another problem - it is not possible to set it on a individual screen-position.
mo_MiniToolbar.PopupMiniToolBar , 1500,1500 <<< ist NOT POSSBILE! ...I think it's because the MiniToolbar fades if it is not in the near of the mouse pointer. Is there any way to show a MiniToolBar on a individual screen-position? |
|
[Sig removed by Admin: Signature can't exceed 40GB]
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
btw maybe such code will work for you. there is SetPopupToolBar method that make context menu looks like minibar:
Option Explicit Public oCmdBar As CommandBar Private Declare Function apiSetFocus Lib "user32.dll" Alias "SetFocus" (ByVal hwnd As Long) As Long Private Declare Function apiGetFocus Lib "user32.dll" Alias "GetFocus" () As Long Private mo_MiniToolbar As XtremeCommandBars.MiniToolBar Private mo_Combo As XtremeCommandBars.CommandBarComboBox Private Sub Command1_Click() oCmdBar.ShowPopup , 5000, 5000 End Sub Private Sub CommandBars1_Update(ByVal Control As XtremeCommandBars.ICommandBarControl) If Control Is mo_Combo Then If Control.Visible Then If apiGetFocus <> mo_Combo.EditHandle Then Debug.Print "Setting Focus " & Timer 'apiSetFocus mo_Combo.EditHandle mo_Combo.Execute ' Set focus for Combo End If End If End If End Sub Private Sub Form_Load() With CommandBars1 Set oCmdBar = .ContextMenus.Add(1, "Test1") With oCmdBar Set mo_Combo = .Controls.Add(xtpControlComboBox, 100, "Test") With mo_Combo .DropDownListStyle = True End With End With oCmdBar.Controls.Add xtpControlButton, 1, "Test1" oCmdBar.SetPopupToolBar True oCmdBar.Width = 400 End With End Sub |
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
Jebo
Senior Member Joined: 27 October 2005 Location: Germany Status: Offline Points: 318 |
Post Options
Thanks(0)
|
Thank you, this will work. :-)
|
|
[Sig removed by Admin: Signature can't exceed 40GB]
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |