• Welcome to PlanetSquires Forums.
 

buttons remain selected

Started by Johan Klassen, July 30, 2018, 07:53:34 AM

Previous topic - Next topic

Johan Klassen

Hi Paul
in my simple calculator, the last button clicked remains selected, it's a problem because if you press the Return or Enter key it will activate that button again, this happens wether the Form KeyPreview is False or True.
however if I click on the Desktop for example and then click on my calculator then none of the buttons are selected, hope this makes sense.

José Roca

#1
Normal. When a button is clicked it gains focus. Detect button clicks and change the focus to the main window with SetFocus <handle of the main window>.

Johan Klassen

thanks José Roca :), that fixed the problem.
I am new to GUI programming and was not aware of this detail.

Johan Klassen

on a related subject, is there a way to un-select an item in a ListBox?
because once an item is selected it remains selected until a different item is selected, I would like for none to be selected.


Johan Klassen

#5
I am afraid that I need more help, I tried the following but I get a "Type mismatch, at parameter 1 of SNDMSG()"
ListBox_SetCurSel(Form1.ListBox1, Form1.ListBox1.SelectedItem)

the following compiles but completely destroys the contents of the ListBox
ListBox_SetCurSel(Form1.ListBox1.SelectedItem.Text, -1)

José Roca

The zero-based index of the item to select, or â€"1 to clear the selection.

ListBox_SetCurSel(Form1.ListBox1, -1)

If Form1.ListBox1 gives you a type mismatch error, the ask Paul. Maybe you have to use Form1.ListBox1.hWindow or something like that.


Johan Klassen

thanks a million José Roca :)
ListBox_SetCurSel(Form1.ListBox1.hWindow, -1) did the trick :)

Paul Squires

Be careful with the ListBox because it is a work in progress at this point. Your approach to send ListBox*.* macro messages to the hWindow property should work without any issues but there are other things in the ListBox that need to be completed before the ListBox control can be considered feature complete.

In your case, do you even want any line in the ListBox to ever be selected/highlighted? If you do not, then you can simply set the ListBox's SelectionMode property at design time to ListSelectionMode.None
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Johan Klassen

Hi Paul
for my calculator I don't want any items to be selectable, your suggestion of setting the ListBox property to ListSelectionMode.None works as advertised, however I don't mind learning a trick now and then.