[Closed] Dotnet controls fighting for focus
I’m trying to have a dotnet combobox+listbox control, where when you press the combobox, it doesn’t drop down, but instead a listbox opens (which would allow mutliple selections).
Up to here everything works great, the problem is that I can’t get the listbox to maintain its focus.
When I click inside the listbox to select items, other controls BEHIND the listbox get focus, even if they are not visible!
Does anyone know what I’m doing wrong?
See attached test code.
try(destroydialog FocusTest)catch()
rollout FocusTest "test" width:240 height:150
(
dotNetControl cb1 "System.Windows.Forms.Combobox" width:200 height:20 pos:[20,20]
dotNetControl cb2 "System.Windows.Forms.Combobox" width:200 height:20 pos:[20,60]
dotNetControl lb "System.Windows.Forms.ListBox" width:200 height:100 pos:[-200,20]
on focusTest open do
(
lb.items.addRange #("1","2","3","4","5","6","7","8")
)
on cb1 MouseDown do
(
cb1.droppedDown=false
lb.pos=[20,40]
lb.BringToFront()
)
on FocusTest lbuttondown pos do
(
lb.pos=[-200,20]
)
)
createDialog FocusTest
hmm you could try your luck with setFocus or temporarily move the hidden ones
I’m reluctant to move the other controls, since it’s about 20 of them, and it would make the interface look weird every time you click a combobox.
what do you mean with setfocus? where would I be using it?
Easily solved by changing the order on how the controls are created:
try(destroydialog FocusTest)catch()
rollout FocusTest "test" width:240 height:150
(
dotNetControl cb1 "System.Windows.Forms.Combobox" width:200 height:20 pos:[20,20]
dotNetControl lb "System.Windows.Forms.ListBox" width:200 height:100 pos:[-200,20]
dotNetControl cb2 "System.Windows.Forms.Combobox" width:200 height:20 pos:[20,60]
on focusTest open do
(
lb.items.addRange #("1","2","3","4","5","6","7","8")
)
on cb1 MouseDown do
(
cb1.droppedDown=false
lb.pos=[20,40]
cb2.visible=false
)
on FocusTest lbuttondown pos do
(
lb.pos=[-200,20]
cb2.visible = true
)
)
createDialog FocusTest
Is this it? Cheers.
Thanks for your responses.
Your solution works in my test example, but not really for my intended use, since I was hoping to use the same listbox for many different comboboxes, moving it to a different place each time, and not have to create a listbox for each one of them.
Do you know if there is a way to change the ‘creation order’ (or really, the z-ordering), after the controls are already created? .BringToFront() does not seem to work.
not afaik
heres a little example of the setFocus fn
rollout ro ""
(
editText et1 ""
editText et2 ""
editText et3 ""
editText et4 ""
timer click active:true interval:500
on click tick do
(
local wich = mod click.ticks 5
if wich == 0 then wich += 1
local item = ro.controls[wich]
if classOf item == editTextControl do setFocus Item
)
)
createDialog RO
tryn write something
Thanks
I’m familiar with the setFocus() method, I was wondering how I could use it in this situation.
if I give the ListBox focus every time it loses focus, I could never focus any other control. :shrug:
Have you tried the BringToFront method in a windows form instead of a rollout? just to check if it works as expected in a form.
well yous aid you only want it to not loose focus when you select an item and loose it, so put it in there, should work … theoretically
It’s a rollout thing, if you can use a Form great, I think your problems will be solved, if not you can add a panel to the dialog and create the controls there, this way you can either use the .Visible property or by moving in and out the listbox (I assume the that using the visible property is better).
Here’s the code:
try(destroydialog FocusTest)catch()
rollout FocusTest "test" width:240 height:150
(
dotnetcontrol panel "System.Windows.Forms.Panel" pos:[0,0] width:240 height:150
local cb1,cb2,lb
fn cb1MouseDown =
(
cb1.droppedDown=false
--lb.Location = dotnetobject "System.Drawing.Point" 10 30
lb.Visible=True
lb.BringToFront()
)
on FocusTest open do
(
cb1 = dotnetobject "System.Windows.Forms.Combobox"
cb1.Location = dotnetobject "System.Drawing.Point" 10 10
cb2 = dotnetobject "System.Windows.Forms.Combobox"
cb2.Location = dotnetobject "System.Drawing.Point" 10 40
lb = dotnetobject "System.Windows.Forms.Listbox"
lb.Location = dotnetobject "System.Drawing.Point" 10 30
lb.Visible = False
--lb.Location = dotnetobject "System.Drawing.Point" -1000 0
lb.items.addRange #("1","2","3","4","5","6","7","8")
dotnet.addEventHandler cb1 "MouseDown" cb1MouseDown
panel.controls.add cb1
panel.controls.add cb2
panel.controls.add lb
)
on panel Click do
(
lb.Visible=False
--lb.Location = dotnetobject "System.Drawing.Point" -1000 0
)
)
createDialog FocusTest