Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box for Fixed Options

Status
Not open for further replies.

newtofoxpro

Programmer
Sep 16, 2007
301
0
0
IN
I am looking for Control which manage Fixed Options to select by user. I found ComboBox is nearly do the job.

Example 1. " Do you want to continue... Yes,No"
Example 2. Debit,Credit followed by Amount.
Example 3. ReportType = Compact,Detail,Summary

I used ComboBox with
this.RowSourceType = 1
this.RowSource = "Debit,Credit"
this.Style = 2

Example 3. Experienced User knows this option, when user wants ReportType Compact user press <C> and <Enter> I want ComboBox should select Compact and move to next control without opening list.

Novice user may not knows so he would enter <X> then ComboBox should open the list to select options.

Please advice any other control to do this job.
 
What exactly is the problem with the combo box? Based on what you have told us, it would seem to do exactly what you want - including being able to select an entry by typing the first letter.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 

Yes, but it open the list. When ComboBox found the Item in the list it should not open the list.
 
Your combobox usage will work fine except with X, but there is a windows hotkey for that - independant of VFP - less known, but also only a single key: F4.

The single key F4 drops down a combobox drop down item list. Also ALT+DOWN ARROW. There is an easy way to make X work that way via
ON KEY LABEL X KEYBOARD '{F4}' PLAIN

BUT: Alert! Warning!
The scope of any ON KEY LABEL definition is global, so anywhere a user types x or X in your application instead F4 is typed, the x is swallowed, even if you don't use the CLEAR clause of KEYBOARD and even if you don't use the PLAIN clause. And that includes Editboxes, so typing texts containing X's then is quite hard. In most cases that only means, the user will think the x key is broken. There is a way out, as you can use the GotFocus() event of the Combobox to define the hotkey and the LostFocus() to undefine it with ON KEY LABEL X, just as this, without any further command clauses, that makes the X key cause X again.

BUT: Alert! Warning!
You also need to undefine hotkeys in Form.Deactivate(), when you change form and the control still has focus. So it's better not to make use of ON KEY LABEL at all. Several here would also advocate not using ON KEY that. In the end it's solvable, but the solution is not centralized, it's spread in control and form events and that means all this is not self explanatory for any developer inheriting such code.

A help topic that discusses easier usage of controls via hotkeys is "How to: Make Controls Easier to Use"
In short you precede the letter you want to use for [ALT]+[?] with \< and it will be displayed underlined to signal this is the letter to use with [ALT] to either select an option or an item.

This also works within Combobox or Listbox items, once you disable incremental search by setting IncrementalSearch=.F., and within the combobox or listbox that does not need ALT. The advantage of course is, you can define hotkeys for items beginning with the same letter, eg \<Companies, C\<ustomers. The hotkey is signaled to the user by underlined letters. And then C selects Companies and U customers, as said without ALT.

Finally:
I'd teach your users the lesson F4 is for combo boxes drop down. It might seem weird and ALT+DWNARROW is an alternative, but if ALT activates the os windows menu of the upper left icon of the window title bar, DWNARROW then drops down that menu instead of the combo box. And F4 is a single key. And you can make use of X for any item with hotkey x, eg E\<xit or any other ex word.

Bye, Olaf.
 
Yes, but it open the list. When ComboBox found the Item in the list it should not open the list.

I don't think so.

If you open a form that contains a combo box, then tab to the combo box, then hit a letter key, the combo will show the first entry that begins with that letter. It does not open the list.

If that is not what you are seeing, there must be some other factor at work.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You need to set the combo's Style to 2-Dropdown List to get the behavior you want.

Tamar
 
Tamar said:
You need to set the combo's Style to 2-Dropdown List to get the behavior you want.

He's already done that. It's the last line of his code in the first post.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 

My users & myself is habituated with <Enter> to pass the focus to next control.

Thank you


Why ComboBox & not textbox ? Only reason to understand users to see when ComboBox appear i.e. there is an option to select.

I would like to use ComboBox, if it works as I want.

Temporary, I have solved my Problem with textbox.

Example of Option : Debit,Credit :

I added object of TextBox

PreValue is = Debit

In InterActiveChange following code added

this.DebitCredit.Value=IIF(UPPER(this.DebitCredit.Value)="D","Debit","Credit")






 
>I would like to use ComboBox, if it works as I want.
It does, in Style=2, I don't know what you're doing that does not work.

RETURN can be made the key to move focus, if you SET CONFIRM ON. But then the more normal TAB won't do.
You could also make use of the KeyPress Event, just ensure form.keypreview is .f., or set forms keypreview .t., if you want the form.keypress prioritized and handle keys central on the form level.

Overall, habits normally are bad, if you enforce behavior on some UI that works different, Foxpro is not access is not winfoorms, is not browser html forms is not silverlight is not flash is not wpf is not Qt is not whatever else you and your users are used to.

Bye, Olaf.
 
I'm wrong about SET CONFIRM, you can still navigate controls via <TAB>, if CONFIRM is ON. I remembered a behaviour, which enforces the user to confirm any data entry with <ENTER>, but that's not the case.

So SET CONFIRM ON is an easy solution to your users being used to use <ENTER> to pass the focus.

Bye, Olaf.
 
Hi,

I would not make use of a combobox in this case but would option for a messagebox. With the advantage you can set the default answer, so when users click enter, the default will be selected/activated.

Jockey(2)
 
MessageBox would be an option, but you also need to display the choice made. Yes/no would be options you can offer, which are bad answers for a question "credit or debit?", even if you make it "creadit(Y) or debit(N)?" Then you rather could do your own messagebox form.

But for mouse users this is a bad interface, as you click somewhere on the form, click on the messagebox, then on the form again, you have to move a lot, then, so this only works for keyboard users.

Bye, Olaf.
 
Olaf,

I agree, Yes/No/Cancel etc are bad options for credit/debit a.s.o. Maybe this could encourage 'NewToFoxpro' to built a messagebox by himselve with options like that?
Unfortunately I dont know how to upload a file to this forum otherwise I would gladly sent him myMessagebox.prg

Regards,

Jockey(2)
 
Newtofoxpro,

I'm sorry to labour this point, but before you start looking for alternative controls, you really need to figure out why your combo box is not working. The default behaviour of a combo box (with Style = 2) is exactly what you are trying to achieve. If it doesn't appear to do what you need, there is something wrong with it. Rather than waste time with looking for a workaround, you should find out what is wrong and fix it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form
Height = 417
Width = 782
ADD OBJECT DbCrAmount as TextBox WITH Top = 100, Left = 90, Height = 24, Value = 0
ADD OBJECT DebitCredit as ComboBox WITH Top = 100, Left = 200, RowSourceType = 1,;
RowSource = "Debit,Credit", Style = 2, Value = "Debit"
ADD OBJECT DbCr as DbCr WITH Top = 100, Left = 310, Height = 24, Value = "Debit"
ENDDEFINE

DEFINE CLASS DbCr as TextBox
PROCEDURE InterActiveChange
this.Value=IIF(UPPER(this.value)="D","Debit","Credit")
ENDDEFINE

***************
I using <ENTER> to move to next Control. <TAB> works fine at ComboBox. Please find the difference between TextBox and ComboBox.

Thanks & Best Regards.
 
Hi,

If you want to stick with the textbox, you may want to set Format to "M" and Inputmask to "Credit,Debit"

ADD OBJECT DbCr as Textbox WITH Top = 100, Left = 310, Height = 24, Value = "Credit", Inputmask = "Credit,Debit", Format = "M"
hth

MarK
 
Your combobox works. What doesn't work with it for you?
If you type CDCDCDCD too fast, incrementalsearch causes the combobox not to switch, because if you type cdc fast, the combobox tries to find an entry starting with C (credit), then with cd (does not exist, stays at Credit) cdc (does not exist, stays at credit). If you only type either C or D you Credit or Debit.

And of course you can turn Incrementalsearch Off, I already told about that option, then use \< as prefix for the "hotkey".

Code:
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form
Height = 417
Width = 782
ADD OBJECT DbCrAmount as TextBox WITH Top = 100, Left = 90, Height = 24, Value = 0
ADD OBJECT DebitCredit as ComboBox WITH Top = 100, Left = 200, RowSourceType = 1,;
RowSource = "\<Debit,\<Credit", IncrementalSearch=.F.,Style = 2, Value = "Debit"
ADD OBJECT DbCr as DbCr WITH Top = 100, Left = 310, Height = 24, Value = "Debit"
ENDDEFINE

DEFINE CLASS DbCr as TextBox
PROCEDURE InterActiveChange
this.Value=IIF(UPPER(this.value)="D","Debit","Credit")
ENDDEFINE

Now you can switch between Credit or Debit as fast as you want.

This is no problem in the normal case, as the user doesn't switch back and forth, but either enters credit, or debit. So what is your problem really?

Bye, Olaf.
 
As Olaf said, your combobox works as you want. So this almost certainly has to be some setting that's different. What VFP settings do you have set to non-default values?

Tamar
 
mjcmkrsr, Your code is very similar to my FPW practice. And you told me how to do this in VFP. Thanks.

@ 12,12 get DbCr pict '@M Debit,Credit' default "Debit "


OlafDoschke, Thank you. I think it is my mistake I could not ask my problem right-way. I am Sorry. Can you stop combobox to open its list when I press <D>/<C> and <Enter>

 
The combobox does not open, when I press either C or D followed by ENTER, instead the focus moves on. The drop down list does neither open in your nor my version. I don't see, what setting would cause a different behaviour. I can only second Tamar, this different behaviour has to come from some setting or perhaps VFP version.

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top