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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box property !! 1

Status
Not open for further replies.

saramaia

Programmer
Aug 5, 2002
61
PT
Hi..

I have a combo box in my form that has a specific size that cannot be changed.

The thing is: some of the items of the combo are larger than the combo size... Do I have a way of showing the complete sentence instead of only the one that has the size of the combo??

Hope i made myself clear...

Thanks in advance,
Sara Maia
 
Hi,

What you could do is take the currently selected items text and display it in the pane of a status bar. Or you might be able to manipulate the control's tooltip text to display the selected item. But that would introduce a delay, you may not want. I'd go for the status bar option myself.

HTH
William
Software Engineer
ICQ No. 56047340
 

I´m not sure i got your idea...

What you´re suggesting is that I show the complete text only of the selected option, right??

Suppose you have two options in the combobox and they differ in the end of the sentence.. and that part is already hidden because of the combo box size..

In that case i would want to see the full text pf both option before selecting one...

In that case, it wouldn´t be enough, am i correct??

Sara Maia
 
Hi,

Yes, the user would need to select the option first, in order to see the text in the status bar.

William
Software Engineer
ICQ No. 56047340
 
Right...

And is´n´t there a way i can do that before he actually selects an option??

I mean, while he is going through the several options...
 
There appears to be a mis-understanding here. I'm using the word select in the contect of the user scrolling down through the list, as the user scrolls through the list the status bar changes accordingly, the list doesn't have to be dropped in order for this to work. You just need to use the proper events.

When the user leaves the control the last item viewed is the item that's been selected (the way it works anyway).

William
Software Engineer
ICQ No. 56047340
 
Yes, i think there is really a mis-understanding :))

Let me see if I understood you.

Imagine i have a combo and when i press the arrow i can see 4 items in the combo....

The thing is i can´t distinguish them because they only differ in the end of the sentence and that part is already hidden...

Suppose i have the combo "opened" and i am going through the items (WITHOUT selecting -> this could be easily atched with Click event)...

Is there an event to catch this??

The thing is: i want to see the full text without selecting it...

Thank you
 
I understand what you are wanting but I don't thing you can do what you want. You may be able to subclass the control and have the drop down list section expand to the right, (you can in C++/MFC) but in VB I don't know how easy it would be.

HTH

William
Software Engineer
ICQ No. 56047340
 
Following is a simple module that allows you to resize the drop down portion of a combobox. If I understood correctly... this is what you were looking for...


Call the sub "ComboSetDropdownWidth" in your Form_Load ev
ent, and pass the width (in pixels) that you require...


Hope this helps....

Giorgio Vidali
Director of Software Development
Automated Business Designs, Inc.


Code:
'Module Name            : mComboSetWidth
'By                     : Giorgio Vidali
'Copyright              : © 1999 Giorgio Vidali & Automated Business Designs, Inc.
'Description            : Contains functions to return/set the width of
'                         dropdown portion of a standard combobox control
'Created                : 08-Oct-99 8:58:39 AM
'Last Update            : 08-Oct-99 8:58:39 AM
'History                : ABD - 08-Oct-99 8:58:39 AM - First Release

'Properties             : n.a.

'Methods                : ComboGetDropdownWidth
'                         ComboSetDropdownWidth

'Sample Calls           : long_value = ComboGetDropdownWidth(cboHwnd:=Combo1)
'                         bool_value = ComboSetDropdownWidth(cboHwnd:=Combo1,NewWidthPixel:=250)
'------------------------------------------------------------------------------------------
Option Explicit

Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const CB_GETDROPPEDWIDTH                  As Long = &H15F
Private Const CB_SETDROPPEDWIDTH                  As Long = &H160
Private Const CB_ERR                              As Long = -1

Public Function ComboGetDropdownWidth(cboHwnd As Long) As Long

    'To get the combo box drop-down width.
    'use this function if you want
    'to change the width in proportion
    'i.e. double, half, 3/4 of existing width.
    'NOTE: return value is in PIXELS
    
    Dim lRetVal As Long
    
    lRetVal = SendMessage(cboHwnd, CB_GETDROPPEDWIDTH, 0, 0)
    
    If lRetVal <> CB_ERR Then
        ComboGetDropdownWidth = lRetVal
    Else
        ComboGetDropdownWidth = 0
    End If
    
End Function

Public Function ComboSetDropdownWidth(cboHwnd As Long, NewWidthPixel As Long) As Boolean
    
    'Set combo box drop-down width
    'to new value specified in passed parm
    
    Dim lRetVal As Long
    
    lRetVal = SendMessage(cboHwnd, CB_SETDROPPEDWIDTH, NewWidthPixel, 0)
    
    If lRetVal <> CB_ERR Then
        ComboSetDropdownWidth = True
    Else
        ComboSetDropdownWidth = False
    End If
    
End Function
 
gvidali:

Your solution worked perfectly for a similar problem I was having.....a star for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top