Results 1 to 11 of 11

Thread: Increasing the width of a combo on the dropdown event. Can i project this increase t

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    California
    Posts
    203
    I am currently using a class that makes an API call to increase the width of my combobox so that the list can be entirely read. I am doing this because space is limited on my form and the only thing the user needs to see is the first two letters. (For example,a list of state abreviations that also shows the full name of the state when it drops down)

    So the problem is, the increase in width projects off to the right. When the dropdown event occurrs, the width is too large and it falls off the screen. I need to know if anyone knows how to handle this event so that the increase in width projects to the left. Or any other sugesstions how I can fix the problem. I can't move the combo box to any other position on the form, so thats out.

    Thanks for any help you might have.

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    Here is something quick i came up with and its very simple:
    Code:
    Private Sub cboState_DropDown()
    cboState.Left = cboState.Left - 600
    cboState.Width = cboState.Width + 600
    End Sub
    
    Private Sub cboState_LostFocus()
    cboState.Width = cboState.Width - 600
    cboState.Left = cboState.Left + 600
    End Sub
    When the drop down event occurs it is expanded to the left and when you loose the focus,
    it returns to its original position.
    Always looking for a better and faster way!

  3. #3
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    ummm...that code has a few bugs in it it works ok though. sorry.
    Always looking for a better and faster way!

  4. #4
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    this is better:
    Code:
    Private lngWidth As Long
    Private lngLeft As Long
    
    Private Sub cboState_DropDown()
    If cboState.Width = lngWidth Then
        cboState.Left = lngWidth - 600
        cboState.Width = lngLeft + 600
    End If
    End Sub
    
    Private Sub cboState_LostFocus()
    cboState.Width = lngWidth
    cboState.Left = lngLeft
    End Sub
    
    Private Sub Form_Load()
    lngWidth = cboState.Width
    lngLeft = cboState.Left
    End Sub
    hehe
    Always looking for a better and faster way!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    California
    Posts
    203

    Thumbs up Thanks!

    After I saw your first idea, I realized what "bugs' you were talking about and started thinking on the same page as you. I will try the new code, thank you so much. you really helped.

  6. #6
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253

    Talking

    you know what? that really is a kewl idea! I am going to
    see if I can create a ComboBox Control that has 2
    properties:

    Item Property for the full text item
    ShortItem Property for an abreviation of the text

    When it is in the normal size, the ShortItem is displayed
    and when it is in the expanded state, it didplays the
    Item.

    Cool idea! It will work great for displaying:

    1) States - Florida, FL
    2) Names - Mike Rodriguez, MR or Mike R
    3) Jobs - Software Engineer, Soft Eng
    Always looking for a better and faster way!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    California
    Posts
    203
    I think that is a great idea. This problem I am finding, (and maybe you can help with this too), is that when the dropdown event fires, the combo box increases as its supposed to. But when the user selects the item they choose, but doesn't lose focus, the combo box remains the increased width. I doesn't look too pretty. The functionality is exactly what I was looking for, but I'm wondering if there is another event that we can resize it back to normal width upon selection of the list item., instead of waiting for the lost focus event. I don't know of any such event, so I thought maybe you would?????



    ?????
    Thanks-

  8. #8
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    oh ya! use the Click Event. It fires when an item is selected
    either by the mouse or the keyboard. You could
    put the resize code into that event as well.
    Always looking for a better and faster way!

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    California
    Posts
    203

    Thumbs up

    You are soooo Cool. Thanks. It works and I'm using it.

    How about solving this one.....?

    If I click on the dropdown, but don't make a change to the selection and i click again, the dropdown goes away but the width doesn't resize. It only resizes on the click event if i select something. So if the user just views the dropdown, but doesn't make a selection, it remains big and still looks a little ugly.

    Given, the user will most likely make a selection. I left the code in the lost focus event also to ensure the resizing, but is there something i could do about when the user doesn't make a selection. What event is triggered to tell the dropdown event to not dropdown anymore?

  10. #10
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    ummm...hehe ...hold on...ill see what i can to.
    Always looking for a better and faster way!

  11. #11
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    hey! I found it...but it is very complicated! Ill give you the code though. This one is a bit rough...

    You cant use it without downloading an update either...
    Code:
    Option Explicit
    
    Implements ISubclass
    
    Private Const WM_COMMAND = &H111
    Private Const CBN_DROPDOWN = 7
    Private Const CBN_CLOSEUP = 8
    Private Declare Function GetDlgCtrlID Lib "user32" (ByVal hwnd As Long) As Long
    
    Private Sub Form_Load()
       AttachMessage Me, Combo1.Container.hwnd, WM_COMMAND
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
       DetachMessage Me, Combo1.Container.hwnd, WM_COMMAND
    End Sub
    
    Private Property Let ISubclass_MsgResponse(ByVal RHS As SSubTimer.EMsgResponse)
       '
    End Property
    
    Private Property Get ISubclass_MsgResponse() As SSubTimer.EMsgResponse
       ISubclass_MsgResponse = emrPreprocess
    End Property
    
    Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
       Dim lID As Long
       Dim iCode As Long
       Select Case iMsg
       Case WM_COMMAND
          If lParam <> 0 Then
             iCode = (wParam And &HFFFF0000) \ &H10000
             ' the id of controls created by VB is the index
             ' of the control in the form's control array plus 1
             lID = wParam And &HFFFF&
             If TypeOf Controls(lID - 1) Is ComboBox Then
                Select Case iCode
                Case CBN_DROPDOWN
                   Label1.Caption = Controls(lID - 1).Name & " Drop Down"
                Case CBN_CLOSEUP
                   Label1.Caption = Controls(lID - 1).Name & " Close Up"
                End Select
             End If
          End If
       End Select
    End Function
    I am not sure if you can do anything with that or not! but...it works. hehe

    That is the only way to do it so far that i know. I have a couple other options that are a little simpler though.
    I can change the width of the dropdown list and keep the combobox at a small width. Its just
    another option.

    Anyways...good luck!
    Always looking for a better and faster way!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width