Combo box handling

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When a user clicks the drop down arrow in my combo box I need to take
different actions depending on whether the user selected an item from the
drop down or did not select an item. How can I distinguish between the two?
In both cases the Click event is triggered.

Also, if my combo box is multi-column, is there any way to tell which column
was clicked on?
 
If no item is selected, the AfterUpdate event does not occur. I normally use
the AfterUpdate event to do something after a user has made a selection.

A combo box does not have "active" columns. When you click on any column in
the dropdown list, that causes the value of the bound column to be written
into the Value property of the combo box, and the record containing that
Value in the bound column is then made active (selected in the combo box).
So the answer is, you cannot tell which column was clicked on.

I suppose you could write code using the MouseDown event to identify the X-Y
coordinates of the cursor's location and then to do a calculation that
identifies which column was under the mouse, but .... well, that is not
something for which a combo box is typically used. If you want to know which
column was "clicked", then it's best to present the data to the user in
separate controls -- that way, you will explicitly know which "column"
(control) was clicked.
 
Thanks for the reply.
Let me explain what I am trying to do any maybe you can offer a suggestion.
I am using a combo box in combination with 2 command buttons to navigate a
tree structure.
The combo box queries the tree structure via a hidden control which holds
the 'parent'. One command button redisplays the top level (parent = 0), the
other command button 'drills down' by resetting the parent to the current
combo box selection and requerying the combo box.
This all works fine except the circumstance where I am positioned on a row
where a drill down is possible and the drill down button is pressed but no
selection is made from the combo box. In this circumstance I am left with the
drill down button displayed even though no drill down is possible.
I need to make the drill-down button invisible if no selection was made in
the combo box after it is pressed because the combo box is then left not set
to a record.
Right now I am totally confused by all the different events involved.

David
 
I solved my problem. All I had to do was to make the drill down button
invisible at the end of its click event procedure.
 
I would suggest that you have code similar to this for the Click event of
the drill down button:


Private Sub DrillDownButtonName_Click()
' do the code to requery the combo box
' (put your code steps here)
' set the focus from the drilldown button to the combo box
Me.ComboBoxName.SetFocus
' make the drilldown button invisible
Me.DrillDownButtonName.Visible = False
End Sub

Then put code similar to this in the ComboBox's AfterUpdate event:

Private Sub ComboBoxName_AfterUpdate()
Me.DrillDownButtonName.Visible = _
(Len(Me.ComboBoxName.Value & "") > 0)
End Sub


What the above code steps do is this:

1) The drill down button is made invisible after it's clicked and it
requeries the combo box. This makes it inaccessible to the user until a
selection is made in the combo box.

2) The drill down button is either made visible or invisible after the user
has selected/entered a choice in the combo box. If the entry is blank (or
the previous entry is deleted), the button is made invisible. If a selection
is made or an entry is made, the button is made visible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top