Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - How to SetFocus to a ComboBox?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to SetFocus to a ComboBox?

 Post Reply Post Reply
Author
Message
Jebo View Drop Down
Senior Member
Senior Member


Joined: 27 October 2005
Location: Germany
Status: Offline
Points: 318
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jebo Quote  Post ReplyReply Direct Link To This Post Topic: How to SetFocus to a ComboBox?
    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]
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 08 February 2011 at 4:22pm
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:


Option Explicit

Private Declare Function apiSetFocus Lib "user32.dll" Alias "SetFocus" (ByVal hwnd As Long) As Long

Private mo_Combo As XtremeCommandBars.CommandBarComboBox

Private Sub Command1_Click()
   apiSetFocus mo_Combo.EditHandle
End Sub

Private Sub Form_Load()
   With Me.CommandBars1
      With .AddMenuBar("Test")
         Set mo_Combo = .Controls.Add(xtpControlComboBox, 100, "Test")
         With mo_Combo
            mo_Combo.DropDownListStyle = True
         End With
      End With
   End With
End Sub

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
Jebo View Drop Down
Senior Member
Senior Member


Joined: 27 October 2005
Location: Germany
Status: Offline
Points: 318
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jebo Quote  Post ReplyReply Direct Link To This Post Posted: 08 February 2011 at 9:29pm
Thanks, but I had tested already with SetFocus-API. But it doesn't work! Thumbs Down
The Cursor is blinking in the ComboBox. But if I press any key, nothing happens! Ouch

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]
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 08 February 2011 at 10:24pm
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

Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 08 February 2011 at 10:35pm
This appears to work okay, but you lose the fade in of the MiniToolbar:


Option Explicit

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.PopupMiniToolBar
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 Me.CommandBars1
      Set mo_MiniToolbar = .AddMiniToolBar("Test")
      With mo_MiniToolbar
         Set mo_Combo = .Controls.Add(xtpControlComboBox, 100, "Test")
         With mo_Combo
            .DropDownListStyle = True
         End With
      End With
   End With
End Sub

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
Jebo View Drop Down
Senior Member
Senior Member


Joined: 27 October 2005
Location: Germany
Status: Offline
Points: 318
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jebo Quote  Post ReplyReply Direct Link To This Post Posted: 09 February 2011 at 1:13pm
Thank you, but it still not work with Mini-Toolbars!

Here is my complete code. So you can see it doesn't work! Ouch

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]
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 09 February 2011 at 2:39pm
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

Back to Top
Jebo View Drop Down
Senior Member
Senior Member


Joined: 27 October 2005
Location: Germany
Status: Offline
Points: 318
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jebo Quote  Post ReplyReply Direct Link To This Post Posted: 09 February 2011 at 3:15pm
> 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]
Back to Top
Jebo View Drop Down
Senior Member
Senior Member


Joined: 27 October 2005
Location: Germany
Status: Offline
Points: 318
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jebo Quote  Post ReplyReply Direct Link To This Post Posted: 09 February 2011 at 4:21pm
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. Dead

mo_MiniToolbar.PopupMiniToolBar , 1500,1500               <<< ist NOT POSSBILE! Ouch

...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]
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 15 February 2011 at 3:38am
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
Back to Top
Jebo View Drop Down
Senior Member
Senior Member


Joined: 27 October 2005
Location: Germany
Status: Offline
Points: 318
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jebo Quote  Post ReplyReply Direct Link To This Post Posted: 15 February 2011 at 3:54am
Thank you, this will work. :-)
[Sig removed by Admin: Signature can't exceed 40GB]
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.