Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - ComboBox.DropDown Event
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ComboBox.DropDown Event

 Post Reply Post Reply
Author
Message
nidzolino View Drop Down
Newbie
Newbie


Joined: 13 December 2024
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote nidzolino Quote  Post ReplyReply Direct Link To This Post Topic: ComboBox.DropDown Event
    Posted: 13 December 2024 at 8:28am
I'm having trouble calling the dropdown menu.
The combobox control does not have a Find function (search by character) but a completely correct name, I developed a function that initially fills the collection and later uses it for searching. AutoComplete is also not enough because it doesn't search for the word that matches within the text of the item, but the beginning of the item.
However, I am facing the following problem. I want to call a drop-down menu (ComboPopUp) right below the ComboBox, so that as the user types, they see the search result immediately.


The problem, as far as I understand, is that I can't call ShowPopUp because xtpBarComboBoxGalleryPopup doesn't have that property! How can I solve this problem?


Private Sub FillData()

   Dim ComboBox As CommandBarComboBox
   Dim ComboPopUp As CommandBar
   Dim Gallery As CommandBarGallery
   Dim Items As CommandBarGalleryItems

   Dim Key As Variant
   Dim count As Integer

   Set ComboBox = MenuBar.Controls.Add(xtpControlComboBox, 999, "&Data", -1, False)
       ComboBox.AutoComplete = False
       ComboBox.Width = 500
       ComboBox.DropDownItemCount = 20
       ComboBox.DropDownWidth = 1000
       ComboBox.DropDownListStyle = True
       ComboBox.EditHint = "Data..."
       ComboBox.CloseSubMenuOnClick = True
       
   Set ComboPopUp = CommandBarsFrame.Add("ComboPopUp", xtpBarComboBoxGalleryPopup)
       ComboPopUp.BarID = 1010
       ComboPopUp.Title = "ComboPopUp"
       
   Set Gallery = ComboPopUp.Controls.Add(xtpControlGallery, 1111, "Gallery")
       Gallery.Width = 1000
       Gallery.Height = 508
       Gallery.resizable = xtpAllowResizeWidth Or xtpAllowResizeHeight
       Gallery.Caption = "Gallery"
       
   Set rstTMP = New ADODB.Recordset

   rstTMP.CursorLocation = adUseClient
   rstTMP.LockType = adLockReadOnly
   rstTMP.CursorType = adOpenStatic

   Set DataItemsListOfICD = New Scripting.Dictionary

   If OpenSQL(rstTMP, clO_LIST_OF_ICD) Then

      Do While Not rstTMP.EOF
         DataItems.Add CVal(rstTMP("GLOICD_ID"), clBT_NUMBER), CVal(rstTMP("GLOICD_Code"), clBT_STRING) & " - " & CVal(rstTMP("GLOICD_Translation"), clBT_STRING)
         rstTMP.MoveNext
      Loop

   End If

   Set Items = CommandBarsFrame.CreateGalleryItems(1212)
       Items.ItemWidth = 0
       Items.ItemHeight = 38
       
       Items.AddLabel "History"
       Items.AddItem 1, "A01"
       Items.AddLabel "All data"

   For Each Key In DataItems.Keys
      Items.AddItem Key, DataItems(Key)
      Items.item(Items.count - 1).Enabled = True
   Next

   Set Gallery.Items = Items
   Set ComboBox.CommandBar = ComboPopUp

   Set Key = Nothing

   Set ComboPopUp = Nothing
   Set Items = Nothing
   Set Gallery = Nothing
   Set ComboBox = Nothing

   Set rstTMP = Nothing

End Sub


Private Sub CommandBarsFrame_CommandBarKeyDown(CommandBar As XtremeCommandBars.ICommandBar, KeyCode As Long, Shift As Integer)

   Dim ComboBox As CommandBarComboBox

   Set ComboBox = CommandBarsFrame.FindControl(, 999)

   If ComboBox Is Nothing Then Exit Sub

   Select Case KeyCode

      Case vbKeyBack
         If Len(ComboBox.Text) > 0 Then
             ComboBox.Text = Left(ComboBox.Text, Len(ComboBox.Text) - 1)
         End If
      Case vbKeyDelete
          ComboBox.Text = ""
      Case Else
          ComboBox.Text = ComboBox.Text & Chr(KeyCode)
   End Select

   Call UpdateComboBox(ComboBox)

End Sub

Private Sub UpdateComboBox(ComboBox As CommandBarComboBox)

   Dim ComboPopUp As CommandBar
   Dim Gallery As CommandBarGallery
   Dim Items As CommandBarGalleryItems
   Dim Key As Variant
   Dim results As Scripting.Dictionary
   Dim count As Integer
   
   On Error GoTo Handler

   count = 0

   Set results = New Scripting.Dictionary

   If Len(ComboBox.Text) > 0 Then
      For Each Key In DataItemsListOfICD.Keys
         If InStr(1, DataItemsListOfICD(Key), ComboBox.Text, vbTextCompare) > 0 Then
            results.Add Key, DataItemsListOfICD(Key)
            count = count + 1
            If count >= 100 Then Exit For
         End If
      Next
   End If
       
   Set Gallery = ComboBox.CommandBar.FindControl(xtpControlGallery, 1212)
       Gallery.Items.DeleteAll
   
   Set Items = Gallery.Items
       Items.AddLabel "History"
       Items.AddItem 1, "A01"
       Items.AddLabel "All data"

   Set ComboPopUp = Gallery.Parent 

   If results.count > 0 Then
      For Each Key In results.Keys
         Items.AddItem Key, results(Key)
         Items.item(Items.count - 1).Enabled = True
      Next
   ElseIf Len(ComboBox.Text) > 0 Then
       ComboBox.AddItem "No results: " & ComboBox.Text
   End If
 
   Set Gallery.Items = Items
   
   Set ComboBox.CommandBar = ComboPopUp
       ComboPopUp.RecalcLayout
       ComboPopUp.RedrawBar

       ComboPopUp.ShowPopup , ComboBox.Left, ComboBox.Top + ComboBox.Height
       
   Dim rs As RECT
   ComboBox.GetRect rs.Left, rs.Top, rs.Right, rs.Bottom
   
   CommandBar.Controls.Find(, 999).CommandBar.ShowPopup , 50, 50
   Set ComboPopUp = ComboBox.Controls.Find(, 999).CommandBar

    ComboPopUp.ShowPopup , rs.Left, rs.Top

End Sub

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.141 seconds.