Hi folks,

Reading Rafael's question about an Escape button reminded me of something 
that's been nagging me for a long time. You can have a Default and a Cancel 
button on a form but the Default button won't work from the keyboard if a 
listbox has focus. It does work if a textbox has focus.

Since a common element of a CRUD form is a listbox and it would seem pretty 
typical for the listbox to have focus when the form opens, and the most 
desirable function for the Default button in this scenario would be to 
execute some action on the data in the listbox, this is fairly annoying. Is 
this "by design" or a bug? See code below for a demonstration.

Thanks.

Ken Dibble
www.stic-cil.org

*** Demo Code ***

PUBLIC oForm

oForm = CREATEOBJECT("MyForm")

oForm.Show()

* As written, the Cancel and Default buttons work properly
* from the keyboard when the form opens. Switch the TabIndex
* values for the textbox and listbox and run it again, and
* the Cancel button works but the Default button doesn't.
DEFINE CLASS MyForm AS Form
      PROCEDURE Init
           THIS.AddObject("Txt1","Textbox")

           WITH THIS.Txt1
                .Top = 5
                .Left = 5
                .TabIndex = 1  && Change this to 3
                .Visible = .T.
           ENDWITH

           THIS.AddObject("CancelButton","Commandbutton")

           WITH THIS.CancelButton
               .Top = 5
               .Left = 120
               .TabIndex = 2
               .Cancel = .T.
               .Caption = "CANCEL"
               .Visible = .T.
           ENDWITH

           THIS.AddObject("List1","Listbox")

           WITH THIS.List1
                .Top = 35
                .Left = 5
                .TabIndex = 3  && Change this to 1
                .RowSourceType = 1
                .RowSource = "One,Two,Three"
                .Visible = .T.
           ENDWITH

           THIS.AddObject("DefaultButton","Commandbutton")

           WITH THIS.DefaultButton
               .Top = 35
               .Left = 120
               .TabIndex = 4
               .Default = .T.
               .Caption = "DEFAULT"
               .Visible = .T.
           ENDWITH
      ENDPROC
ENDDEFINE 


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to