oursmp
04-01-2005, 05:25 AM
Hi,
I have an activex control which is a combination of a label and standard combo box. I need to re-size the comobox’s drop down list items’ width based upon the item with the largest width in the combo box list items, so that the items are visible completely, irrespective of them being greater than or less than the combo box width (or activex control in this case).
By the code below, I am able to achieve that with a standard combo, but I am unable to do the same with my activex control.
My Code in the Activex control:
---------------------------------------------
Public Sub SetDropDownWidth()
Dim RetVal As Long
Dim PixelWidth As Long
Dim MaxWidth As Long
Dim LoopCounter As Long
Dim lWidth As Long
For LoopCounter = 0 To cboDropDownCombo.ListCount - 1
lWidth = cboDropDownCombo.Parent.TextWidth(cboDropDownCombo.List(LoopCounter))
If lWidth > MaxWidth Then
MaxWidth = lWidth
End If
Next LoopCounter
MaxWidth = 2000
MaxWidth = MaxWidth + (23 * Screen.TwipsPerPixelX)
If MaxWidth > (cboDropDownCombo.Width * 2) Then
MaxWidth = (cboDropDownCombo.Width * 2)
ElseIf MaxWidth < cboDropDownCombo.Width Then
MaxWidth = cboDropDownCombo.Width
End If
PixelWidth = (MaxWidth \ Screen.TwipsPerPixelX)
RetVal = SendMessage(cboDropDownCombo.hWnd, CB_SETDROPPEDWIDTH, PixelWidth, 0)
End Sub
I am getting the following error at the bolded line (the line starting with lwidth and ending with ‘(loop counter))’:
Run-time error ‘382’:
‘CanGetFocus’ property cannot be set at runtime. The same code does not give this error when I am dealing with a standard combo box instead of my custom acitvex control. Please help me resolve the error.
Thanks in advance
Ourspt
I have an activex control which is a combination of a label and standard combo box. I need to re-size the comobox’s drop down list items’ width based upon the item with the largest width in the combo box list items, so that the items are visible completely, irrespective of them being greater than or less than the combo box width (or activex control in this case).
By the code below, I am able to achieve that with a standard combo, but I am unable to do the same with my activex control.
My Code in the Activex control:
---------------------------------------------
Public Sub SetDropDownWidth()
Dim RetVal As Long
Dim PixelWidth As Long
Dim MaxWidth As Long
Dim LoopCounter As Long
Dim lWidth As Long
For LoopCounter = 0 To cboDropDownCombo.ListCount - 1
lWidth = cboDropDownCombo.Parent.TextWidth(cboDropDownCombo.List(LoopCounter))
If lWidth > MaxWidth Then
MaxWidth = lWidth
End If
Next LoopCounter
MaxWidth = 2000
MaxWidth = MaxWidth + (23 * Screen.TwipsPerPixelX)
If MaxWidth > (cboDropDownCombo.Width * 2) Then
MaxWidth = (cboDropDownCombo.Width * 2)
ElseIf MaxWidth < cboDropDownCombo.Width Then
MaxWidth = cboDropDownCombo.Width
End If
PixelWidth = (MaxWidth \ Screen.TwipsPerPixelX)
RetVal = SendMessage(cboDropDownCombo.hWnd, CB_SETDROPPEDWIDTH, PixelWidth, 0)
End Sub
I am getting the following error at the bolded line (the line starting with lwidth and ending with ‘(loop counter))’:
Run-time error ‘382’:
‘CanGetFocus’ property cannot be set at runtime. The same code does not give this error when I am dealing with a standard combo box instead of my custom acitvex control. Please help me resolve the error.
Thanks in advance
Ourspt