resize of combobox does not work

K

King Albert II

Hi,

I have a form with a combobox. Its width is set to 78 using the
properties gui, 1st column is bound and 2 columns should display when
open.

The rowsource of the combobox is a 2 column range, set in code, works
fine.

These 2 colums combined are broader than 78, so while it is clicked open,
I want the combobox to resize to 100, overlapping the controls to its
right.

After the user makes her selection, I want to resize back to 78.


Below the eventhandlers concerned. The _change event is 'the revert to
normal' part. I fires allright, but not only does the combobox remain at
100, its arrow disappears. Repainting doesn't do anything.


What does work is to insert a msgbox after setting the width ???
When OK'd, the combobox width is back to 78, with arrow.


thx for any advice

Ward




Private Sub afdeling_Change()
artikeldimensies.afdeling.Width = 78
'msgbox "I was here"
End Sub

Private Sub afdeling_DropButtonClick()
artikeldimensies.afdeling.Width = 100
End Sub
 
D

Dave Peterson

Have you thought about just using the _enter and _exit events?

They seemed to work ok for me.

Option Explicit
Private Sub afdeling_Enter()
Me.afdeling.Width = 100
'Me.Repaint
End Sub
Private Sub afdeling_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.afdeling.Width = 50
'Me.Repaint
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.afdeling.AddItem "AAAAAA" & iCtr
Next iCtr
Me.TextBox1.SetFocus
Me.afdeling.Width = 50
End Sub

I added the me.repaint lines just to make sure the form gets updated correctly.
But they didn't seem necessary. The userform updated nicely.

I left the lines in the code in case you had trouble and wanted to uncomment
them to test to see if that helped.

ps. I used the Me keyword. That represents the object that owns the code.
That way, I don't need to know (or provide) the name of the userform within the
code.

pps. The combobox width stays wide until the user activates a different
control. That doesn't seem like a bad idea from a user standpoint to me. I
could see what I chose.
 
K

King Albert II

You got me thinking and I figured it out.

Within the _change eventhandler I needed to set focus to the adjacent
control.

thx for your help

Ward.





Private Sub afdeling_Change()
Me.segment.SetFocus
Me.afdeling.Width = 78
End Sub

Private Sub afdeling_DropButtonClick()
Me.afdeling.Width = 100
End Sub
 

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

Top