Little trouble [solved]
Posted: Fri May 01, 2020 4:30 pm
Hi to all.
Below is the simple code that shows the problem. It does not always occur, but often. This is not critical, but only a cosmetic effect. However, it is annoying. I decided to duplicate mouse actions so that I could select items using the keyboard.
So... run the code several times(F5 in IDE again and again) to catch the problem.
After starting, press the <Tab> key once to shift focus to combo1. Right after that, press <Enter> to expand combo1. Now you can see that selected row is not equal to the first element. The same goes for combo2. Why? Prior to this, on lines # 24 and # 29, I forced the first element to be set as active.
I also tried to fix it with API, but did not give a positive result. How to fix it? Please, help me.
Below is the simple code that shows the problem. It does not always occur, but often. This is not critical, but only a cosmetic effect. However, it is annoying. I decided to duplicate mouse actions so that I could select items using the keyboard.
So... run the code several times(F5 in IDE again and again) to catch the problem.
After starting, press the <Tab> key once to shift focus to combo1. Right after that, press <Enter> to expand combo1. Now you can see that selected row is not equal to the first element. The same goes for combo2. Why? Prior to this, on lines # 24 and # 29, I forced the first element to be set as active.
I also tried to fix it with API, but did not give a positive result. How to fix it? Please, help me.
Code: Select all
Procedure.s OpenChildWindow()
Protected Ret.s = ""
Protected Exit
Child_Wnd = OpenWindow(0, 0, 0, 300, 200, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If Child_Wnd
TextGadget(1, 10, 15, 70, 20, "Str #1:")
TextGadget(2, 10, 50, 70, 20, "Str #2:")
cb1 = ComboBoxGadget(4, 90, 13, 200, 25)
cb2 = ComboBoxGadget(5, 90, 48, 200, 25)
EditorGadget(6, 10, 85, 280, 80, #PB_Editor_ReadOnly)
btn = ButtonGadget(8, 210, 170, 80, 25, "Ok")
AddKeyboardShortcut(0, #PB_Shortcut_Return, 100)
SetForegroundWindow_(Child_Wnd)
AddGadgetItem(4, -1, "Alfa")
AddGadgetItem(4, -1, "Bravo")
AddGadgetItem(4, -1, "Charlie")
AddGadgetItem(4, -1, "Delta")
AddGadgetItem(4, -1, "Echo")
AddGadgetItem(4, -1, "Foxtrot")
SetGadgetState(4, 0)
For i=0 To 15
AddGadgetItem(5, -1, Str(i))
Next i
SetGadgetState(5, 0)
SetActiveGadget(-1)
Repeat
Event = WaitWindowEvent()
Window = EventWindow()
If Window = 0
If Event = #PB_Event_CloseWindow
RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
Exit = #True
ElseIf Event = #PB_Event_Menu
Select EventMenu()
Case 100
ag = GetActiveGadget()
If ag = 4
If SendMessage_(cb1, #CB_GETDROPPEDSTATE, 0, 0)
SendMessage_(cb1, #CB_SHOWDROPDOWN, 0, 0)
Else
SendMessage_(cb1, #CB_SHOWDROPDOWN, 1, 0)
EndIf
ElseIf ag = 5
If SendMessage_(cb2, #CB_GETDROPPEDSTATE, 0, 0)
SendMessage_(cb2, #CB_SHOWDROPDOWN, 0, 0)
Else
SendMessage_(cb2, #CB_SHOWDROPDOWN, 1, 0)
EndIf
EndIf
EndSelect
ElseIf Event = #PB_Event_Gadget
Gadget = EventGadget()
If Gadget = 4
ElseIf Gadget = 5
ElseIf Gadget = 8
EndIf
EndIf
EndIf
Until Exit
CloseWindow(0)
ProcedureReturn Ret
EndIf
EndProcedure
OpenChildWindow()