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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SEARCH AND ADD IN COMBO BOX 1

Status
Not open for further replies.

harryjr

Programmer
Jan 4, 2001
27
0
0
US
Is there any way to use a COMBO BOX that will

(1) permit use of an ARRAY* for SOURCE
(2) incremental search as each CHARACTER is input
(3) show "hit" (hi-lite found item in drop down list)
(4) if entered item not in ARRAY - ADD item to ARRAY

* The DATA for the LIST is in a Table. I think it would
be easier to ADD an item to the TABLE using an ARRAY.

I've tried KB Article Q139769 - How to Add a New Value to a List of Values in a Combo Box but it doesn't work. The article uses a LIST of items as RowSource Property rather
than an ARRAY.

Any help will be greatly appreciated.

HarryJr
 
harryjr

I have a combination of 2 classes that may help you.

To use the class called SuperCombo, you drop it onto a form and set its .Left property to 800. You then add another class called cmdDnArrow which simulates the down arrow part of a combobox, immediately to the right of a standard textbox.

Clicking on cmdDnArrow will then position SuperCombo underneath the textbox, simulating a combobox.

Tabbing from the textbox will take you into SuperCombo, which is based on a grid. Keyboard or mouse selection removes SuperCombo, and replaces the textbox value with the value from SuperCombo.

You need only one SuperCombo control per form, but you can use as many cmdDnArrows as you like to convert existing or new textboxes.

You should also add a standard checkbox to the form, called .chkAutoOpen.

If this is enabled,then as each textbox gets focus, SuperCombo will open accordingly.

To perform an incremental search, you need code in the .KeyPress event of a textbox, and with SuperCombo open you can see the search in progress.

IMHO, comboboxes are fragile and fickle. By basing this simulation on a grid, the performance issues of a combobox no longer apply and you then have the scope to embed controls in the grid, edit, delete, scroll laterally and so on.

I have a demo form, class library, etc and will send it to you if you think it might help. It does not add the value in a textbox to the lookup table, but that is simple enough to do.

If you want to try it, (77KB .zip) post your e-mail address

Chris

 
harryjr

Typo - apologies

If this is checked, then as each textbox gets focus, SuperCombo will open accordingly.

Chris
 
Harry, it is quite complicated thing to organize such functionality using combo box. It is much better to make it using a signe text box, grid and button. Button will simulate drop-down functionality of the combobox. Grid will show drop-down part of the combobox. Quick search in the text box is discussed in many threads here and at the Universal thread. Grid as simulation of drop-down part is also quite popular.

This way ismuch flexible than trying to workaround combobox.

Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Chris,

Would like to try your class combo. Email address below.
Thanks for the response.

Harry
hriley9@bellsouth.net
 
would you like to send me to it Chris

Thanks

Soykan OEZCELIK
soykanozcelik@hotmail.com Soykan OZCELIK
Comp.Prog / MSFoxPro Programmer Developer
 
Sounds intresting ,Would like to try your class combo. Email address below.
Thanks for the response.

Gerardo
gserna9@axtel.net
 
Chris,

Sounds VERY GOOD.
I can see all kinds of applications for a FPD to VFP conversion I am in the middle of. If you are not too tired of mailing by now, I would love to check it out.

Thanks -

stevesmith@sofasource.com
 
Harryjr,
I have had many experiences with what you are seeking to do. I am a little baffeled by how no one wants to use a "ComboBox" as it's intended to be. It is only marginally tricky, but once you build a single class for it, it is very fast, and very nice. The biggest leap, I seem to find is most programmers are not comfortable dealing with Array's. Fox, however (as you probably know, based on your post above), has a great number of commands for manipulating arrays. Take an hour one afternoon, and just play around with them. You will be familiar quickly with their abilities. I'll try to provide some additional info here on how to best utilize Combo Box functionality.
VFP provides an excellent ComboBox, but it needs just a little bit of help. Creat a CombBox subclass, and add the following property:
ARRAYSOURCE[1] (When defining the property, enter it exaclty that way. This will tell VFP that you are creating an Array Property. When you view it in the Others tab, at the bottom, it will appear like this:
arraysource(1,0)
If it doesn't look like that, delete it and try again, because it's not right.
Now, in the Data tab, DO NOT set a Control Source value. (After 3 nights of pulling out my hair, I finally discovered, this can cause LOTS of problems.)
Next, in your RowSourceType, make it 5 - Array.
In your RowSrouce make it This.ArraySource

One of the interesting things about VFP ComboBoxes, is that there are really only 2 "RowSourceTypes" that really allow it to work as an effective ComboBox. (A box that allows you to either pick from a list, or CREATE new items.) They are 1 - Value, and 5 - Array. In reality, only type 1 will allow the use of the "AddListItem" method. But, the beauty of Fox is, the Array can be manipulated externally, and then "Updated" (or Requery()) as it changes. To do this, simply place "This.Requery" after any code in your combo box that changes the Array contents. (You don't need to do it simply after picking a new item, it's not necessary).
Now, in your Init Event, you will need to do something to populate your Array. (Usually, my Array is created based on some type of SQL statment, but it can be by any means which you create your array.) This is where the ArraySource comes in, for example, I might populate my array with:
SELECT DISTINCT TRANSACTYPES FROM TRANS INTO ARRAY This.ArraySource

Note that the "This.ArraySource" only works "Inside" this object, but you can populate it from other locations with:
ThisForm.ComboBoxName.ArraySource = <blah, blah, blah>

Where Blah are your Elements.
Creating the ArraySource proprty is important for establishing the Array in the control. Outside of that, you can then DIMENSION or populate it otherwise in any way you see fit. I frequently use multi-element arrays in my ComboBoxes, so that what my User picks, isn't necessarily the explicit value I'm going to act on, but rather some other column in the Array. (I suspect you get the idea).
Now, as for your incrmental search, there is an EXCELLENT method for this kind of thing, which is InteractiveChange Event. Because, InteractiveChange event fires *EVERY* time a value in the combo box changes. You can use things like ASCAN() in your interactive change to locate the value you have just entered, and begin to populate your &quot;DisplayValue&quot; or &quot;Value&quot; properties as appropriate. (I will admit, I have not done this specifically with a ComboBox, but I see no reason why it won't work. I use this process in a number of textboxes I have all the time, and fundamentally, a ComboBox is just a textbox with some added functionality.)
Also, I, in my LostFocus event, will take care of not have a ControlSource property set to the ComboBox. The reason for not setting a ControlSource is, if you are trying to save/display an item that for whatever reason is not in the list, VFP will display an EMPTY combo box if the ControlSource's value is not found in your ArraySource. So, (for instance, while you're adding a new item that doesn't already exist...) you'll want to keep your ComboBox happy by not &quot;Hooking&quot; it to a ControlSource. In the LostFocus event, it's easy enough to do a couple of things, but usually, I update the table directly with a good old fashioned &quot;REPLACE&quot; statment. Such as:
REPLACE TRANS.TRANSTYPE WITH This.Value

Also, in the Combo's REFRESH() method, you'll need to provide the value from the current field to the ComboBox, so that when say your record pointer changes, the ComboBox is sufficently updated.
Aside from the fact that you have some code to provide to get the specific functionality you want, (and without your spec's, I can't write it for you! :) ), this should provide everything you need to create a robust, single instance ComboBox to your form. Once you've done it once, it's good forever.

Best Regards,
Scott

Please let me know if this has helped [hammer]
 
Thanks to those who have expressed an interest in SuperCombo.

I am going to write a FAQ called :-

How can I convert a Textbox to a Combobox?

and will advise in this thread when it is done.


The methodology in the FAQ will use additional form properties and methods, as opposed to properties and methods in sub-classed controls.

The illustration will be for the simplest variant, that being the conversion of any existing textbox.

When the textbox receives focus, it &quot;converts&quot; itself to a SuperCombo by placing a headerless grid immediately underneath and a small commmandbutton immediately to the right, thus visually simulating a combobox.

When the textbox loses focus, it reverts to its original state as the grid and commmandbutton disappear.

Should the next textbox tabbed to or clicked on also be set to convert to SuperCombo, then the process repeats itself.

Whilst in SuperCombo &quot;mode&quot;, the keyboard, mouse, commandbutton and grid behaviour is determined by the developer with far greater control than is possible with a convential combobox.

If preferred, you can set up commandbuttons for each textbox, to visually simulate comboboxes in their unexpanded state.

As you now have a grid as the list control, the combobox record number limit of between 500 and 2000 records, (before flakiness sets in), is no longer a problem.

Being a grid, you cannot use an array as a controlsource, but with only 65,000 elements available, you are also likely to run out of resources there as well.

By comparison to a cursor or table, an array is also limited in its data manipulation capabilities.

Any comments, ideas, suggestions, etc on the above would be appreciated before committing to the FAQ. HTH

Chris [pc2]
 
Mar 25, 2002

would like to try your combo
please email it to
klaus.briesemeister.kb@bayer-ag.de

should you ever need a translation english/german oder german/english - perhaps I could
help you too by trying best I can.

regards from germany
Klaus
 
Would also like to try this. Thanks in advance.

batfink21@hotmail.com
 
Chris,
I have would love to try your SuperCombo if you're not tired of emailing it to a million eager VFPers.
Christian (cmendes@kalintechnology.com)
 
Hi Chris,
May I try your SuperCombo? Please email it to
peter.wu@draeger.com.au
 
Just so everyone knows there is a comboclass available in the faq I posted a while ago the works like the &quot;autofill&quot; feature in Quicken or Internet Explorer, and someone requested that I modify it to allow add the &quot;not found&quot; value to the Rowsource table. If anyone is interested I'll gladly e-mail it.

 
I have edited the faq184-1792 with the new code to allow adding the value not found in the lookup table.
 
Hi, Chris!
Please email me the combo class at
bootmaker@hotpop.com
 
Chris, I am in desperate need (over budget, over schedule - and using a combobox on 69,000 records) of your super combo.

mikea@mchsi.com

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top