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!

combo box without arrow 1

Status
Not open for further replies.

tazardous

Programmer
Aug 22, 2002
58
0
0
US
Hi everyone,
I have a client, who would like the functionality of the combo box (dropdown list), but doesn't want the little right arrow image on the field. Is there a way to have the functionality and look (i.e. one 'line' of text displaying until entered) of a combo box, but without the arrow?

 
Can't think of a way by default....but:

Create a text box.
Place a list box directly below and set the visible property to no.
Using the OnClick of the text box, set the visible property of the list box to yes
Using the OnClick event of the list box, set the text box equal to the list box and then set the visible proptery of the list box back to no.

That should pretty much simulate the effect you are looking for.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Thank you for the idea. It works to the customers satisfaction except for the case where they click on the textbox but decide NOT to click on one of the NOW visible selections. Rather they want to leave as is the values and click somewhere else. Since the textbox is still visible (no onclick event firec to close it), I tried commanding it to invisible in an 'lost focus' event. But that fails, because apparently it still has focus when the user attempts to click on something else.

Any idea how I can accomplish this?

Thanks,
Brian
 
How are ya tazardous . . . . .

I remember I once had to do the same thing once, but for some other reason. I remember using a [blue]textbox on top of a listbox, controling the visibility of the list box[/blue].

I remember it worked just fine and you can get it to work just like a combo! I'm trying to find the DB I used it in (so many) or perhaps my library notes to see if there are any particulars of concern. But I don't remember any. I believe you should have no problem . . . .

cal.gif
See Ya! . . . . . .
 
Hi,
Actually, I changed it to a listbox already too. So the scenerio is the same. Again, I need to stress, the use of the listbox, and it's becoming visible and invisible when a selection is clicked, works fine. But, if the user decides AFTER the listbox is visible, to click away, onto some other control, the listbox remains visible and that's no good.

BTW - nice to see calvin!

Taz
 
tazardous!

Found the DB I was looking for! What I had to do was add the following line to the [blue]Got Focus Event[/blue] of all the other controls. There were quite a few, but it was worth it! It Looks good! Has light blue backgroung with dark blue text . . .
Code:
[blue]If Me!Name.Visible Then Me!Name.Visible = Not Me!Name.Visible[/blue]
From My Notes: an easier way would be to use the [blue]Mouse Move Event[/blue] for the form (with the same code above). This way when you leave the area of the ListBox it would automatically hide. But [blue]Mouse Move[/blue] will be continually running as long as the form is open (it has to return the current xy position), and I have disfavor for a routine that does that. This was the reason why I populated all the other controls with the code. Maybe you won't see it that way! ;-)

cal.gif
See Ya! . . . . . .
 
tazardous
Not sure whether or not this will assist, but Microsoft sample forms includes an item called "How to hide the combo box drop down arrow." The sample combo box is an Employee combo box control.

I copied the text that explains the procedure. The text is as follows...
"The Employee control is a combo box. The drop-down arrow is covered with a borderless rectangle with the background to match the underlying control. When the combo box has the focus, the arrow is visible."

So, all that has been done is to put a small borderless transparent rectangle over the arrow. As soon as the combo box has the focus the arrow appears. When focus is lost the arrow is covered up.

If it's the case that you never want an arrow to appear then this isn't a fix you would want. However, I thought I would throw it in as it looked interesting.
Tom
 
ok,
Thanks, yes that does work. But as you said, that's a lot of events to code.... Especially on the form I am working with. Not to mention I will have about 20 controls that 'could' have their listbox visible.
I'll have to see if I can 'generize' it so that I can call a generic routine throughout. Perhaps then it would be worth doing.
In the back of my mind it seems I heard of a function that returns a value (name) of the previous 'got focus' control. If that were true, I probably could write a function that I call each time that would cover this situation. Too bad the 'lost focus' of the listbox controls can be used to make themselves invisible.

thanks,

to be continued...
 
tazardous!

Was just going to bed when it hit me . . .

From the [blue]Lost Focus Event[/blue] of the ListBox, you could set a short [blue]Timer Event[/blue], say . . . . 50 milliseconds that hides the ListBox and and stops the timer!

I'm gonna try it in the mourning . . . . . .

cal.gif
See Ya! . . . . . .
 
if the user decides AFTER the listbox is visible, to click away, onto some other control, the listbox remains visible and that's no good

Your problem appears to be happening because you cannot hide a control that has the focus. So, why not simply move the focus to another control?

Assume the text box is called txtName, the list box is lboName and another control is called txtAddress. In the lost focus event of the list box, try this....

me.txtAddress.SetFocus
me.lboName.Visible=False


Randy
 
Yes, exactly, the problem is that one can not hide a control that has the focus. Moving the focus to another, arbritrary control, would no doubt confuse the user, whose very action was to click on another control of their choosing. Now, if I could KNOWN what control they were clicking 'to', I could make an intelligent change of focus. Is there something that will give me the name of the control that the user is trying to 'click to'?

Thanks

Taz
 
You could include code to hide the list box on the got focus event of every control on the form.

Randy
 
Thanks Randy700, but that option, while valid, was discussed earliar in this tread and frankly would be a lot of coding (over 140 controls on this form - yes, I know, it's not pretty, but despite my efforts of persuasion, this is what the client wants), with over 20 controls that have to be checked (shown or hide) everytime a user clicked on one of the controls).

Taz
 
Hay tazardous . . . .

First, [blue]randy700[/blue] suggestion is a good one, but consider:
TheAceMan said:
[blue] If the user clicks in some other control, and the [purple]Lost Focus[/purple] event of the ListBox sets the focus to some other control, [purple]the user will be robbed of where they wanted the focus to go![/purple][/blue]
This is inconsistent with normal operation. Not being aware . . . . [purple]the user will probably loose the cursor position[/purple].

I tried the [blue]Timer[/blue] routine this mourning, and it works great (Already sent Change Order to that company). You could include a code line for each ListBox thats setup this way.

You should try it!

cal.gif
See Ya! . . . . . .
 
Hey AceMan1,
could you provide the code for that event????
Earlier you said you were put it in the LOST FOCUS event for the listbox. So basically you have something like:

wait 50 milliseconds
me.listboxname.visible = false


is it the delay what makes this work? Because just hiding the control fails since the control still has focus.

thanks,

Taz
 
tazardous . . . . .

I have a meeting to go to that will take up the rest of my time at work. Then its home . . . . I'll give it all to ya then . . . . . around 6:30 . . . . 7ish EST!

cal.gif
See Ya! . . . . . .
 
OK taz . . . . Here we go!

The problem is, we can't hide the ListBox because of code running in an event like On Lost Focus. [blue]So the Idea is to let the event complete and the focus go where ever it wants[/blue]. This is the function of the timer.

That done, we could now do what we want if we knew where the focus ran off to! I realized I could use the [blue]Screen Object[/blue] along with the [blue]ActiveControl property[/blue] to do just that! So lets get on with code. [purple]Don't forget to backup the DB before making any chages[/purple]. Also throughout this post, [purple]LBN[/purple] = YourListBoxName & [purple]TBN[/purple] = YourTextBoxName.

First we have to set a private constant to contain the delay time for the [blue]Timer Interval[/blue] event (this is the time in milliseconds). This is just a common location where you can change the value, instead of having to replace it many times in code (this is mainly for you, as you say you have more than one ListBox). So add the following to the [blue]Declarations Section[/blue] of your [blue]Form Module[/blue]:
Code:
[blue]Private Const MyDly As Long = 50 [green]'milliseconds[/green][/blue]
Next, the code for the [blue]On Timer[/blue] event. Its here the [blue]Screen Object[/blue] is used to tell which control has the focus. If the ListBox or the TextBox on top of it does not have the focus, the ListBox is hidden! What ever happens, the timer is always stopped here. Add the following to the form [blue]On Timer[/blue] event:
Code:
[blue]   Dim curCtl As String
   
   curCtl = Screen.ActiveControl.Name
   
   If curCtl <> "[purple][b]LBN[/b][/purple]" And curCtl <> "[purple][b]TBN[/b][/purple]" Then
      Me![purple][b]LBN[/b][/purple].Visible = False
   End If
         
   Me.TimerInterval = 0 [green]'Stop The Timer[/green][/blue]
Next, to activate the timer routine, we add [blue]myDly[/blue] to the [blue]On Lost Focus[/blue] event [purple]for both the TextBox & ListBox[/purple] with the following code:
Code:
[blue]Me.TimerInterval = MyDly[/blue]
So when either control loses focus, the timer starts running, the focus event completes, the cursor goes to some control, and the [blue]On Timer[/blue] routine takes over when the [blue]Timer Interval[/blue] runs out. [purple]This is the key operation that makes it work![/purple]

A few more routines to complete operations . . . . .

Add the following code to the [blue]On Click[/blue] event of the TextBox:
Code:
[blue]   Me![purple][b]LBN[/b][/purple].Visible = Not Me![purple][b]LBN[/b][/purple].Visible[/blue]
This simply toggles the ListBox between visible/hidden.

We still have to allow for making a selection in the ListBox. So add the following to the Listbox [blue]After Update[/blue] event:
Code:
[blue]   Me![purple][b]TBN[/b][/purple] = Me![purple][b]LBN[/b][/purple].Column([green][b]1[/b][/green]) [green][b]'Correct Number For Your Column![/b][/green]
   Me![purple][b]TBN[/b][/purple].SetFocus
   Me![purple][b]LBN[/b][/purple].Visible = False[/blue]
One last optional item. ListBoxes have a nasty habit of showing a faint line under the first row. Add the following code to the forms [blue]On Open[/blue] event to take care of it:
Code:
[blue]Me![purple][b]LBN[/b][/purple].Requery[/blue]
Thats it taz. Give it a whirl and let me know!

cal.gif
See Ya! . . . . . .
 
Thank you, thank you, thank you for taking the time to lay things out for me so well. Although I have not tried this, it certainly looks good and I have every reason to believe it will work.

For all your hard work, you deserve a 'star'.

taz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top