combo width
Hello .
I want to change the width of a combobox depending on the selected item . My code doesn't work good , it also doesn't limit the width when the item is longer than the form1 .
Dim m_MaxWidth As Integer
Dim m_Width As Integer
With Combo1
m_MaxWidth = Form1.Width - .Left
m_Width = TextWidth(.List(.ListIndex))
If m_Width > m_MaxWidth Then m_Width = m_MaxWidth
.Width = m_Width
End With
thanks .
[493 byte] By [
EI00618] at [2007-11-15 17:37:33]

# 1 Re: combo width
private Sub Combo1_Change()
Call resizeCombo
End Sub
private Sub Combo1_Click()
Call resizeCombo
End Sub
private Sub Form_Load()
Combo1.AddItem "sAKDJHFALKSJH"
Combo1.AddItem "kjshfrg"
Combo1.AddItem ".ds,fv"
Combo1.AddItem "sdlfnb"
Combo1.AddItem "dslfhsd"
Call resizeCombo
End Sub
'
private Sub resizeCombo()
Dim m_MaxWidth as Integer
Dim m_Width as Integer
With Combo1
'around 400 is the size of button to the right
'of combo. You have to set the width = width
'of text + button width
m_MaxWidth = Form1.Width - .Left - 400
If .ListIndex <> -1 then
m_Width = TextWidth(.List(.ListIndex))
else
m_Width = TextWidth(.Text)
End If
m_Width = m_Width + 400
If m_Width > m_MaxWidth then
m_Width = m_MaxWidth
End If
.Width = m_Width
End With
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make dev-archive a great place.
Come back soon, you Gurus.
The Rater
# 2 Re: combo width
Hi ... , thanks for your help ... , but the application crush in this line :
m_Width = TextWidth(.List(.ListIndex))
when the text are longer than the form1 ...
May be it's due to my application design ...
# 3 Re: combo width
Dim your variables as single
ie:
Dim m_Width As Single
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make dev-archive a great place.
Come back soon, you Gurus.
The Rater
# 4 Re: combo width
Thank you so much ... , that works .
# 5 Re: combo width
Have a nice day
;-)
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make dev-archive a great place.
Come back soon, you Gurus.
The Rater