Results 1 to 3 of 3

Thread: [RESOLVED] Blanking text of a Dropdown List style ComboBox

  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Resolved [RESOLVED] Blanking text of a Dropdown List style ComboBox

    This is another one I've struggled with. I like the "Dropdown List" style of a ComboBox for certain applications. However, there are times when I need to "blank" it out. You can't just do cbo.Text = vbNullString, as the .Text property is read-only.

    The only way I've found to do it is to use the .Clear method, and then re-load the list. It's the re-loading of the list that's sometimes a pain.

    Anyone figured out how to clear the text without clearing the list?

    Thanks,
    Elroy

    EDIT1: See, here's what I wind up doing, which is ugly. The cmd is just a "Clear" button. In this example, there are actually control arrays of cbo and cmd controls.

    Code:
    
    
    Private Sub cmd_Click(Index As Integer)
        Dim s() As String
        Dim i As Long
        '
        ReDim s(0 To cbo(Index).ListCount - 1)
        For i = 0 To cbo(Index).ListCount - 1
            s(i) = cbo(Index).list(i)
        Next i
        cbo(Index).Clear
        For i = 0 To UBound(s)
            cbo(Index).AddItem s(i)
        Next i
    End Sub
    
    
    Last edited by Elroy; Aug 17th, 2017 at 10:11 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Blanking text of a Dropdown List style ComboBox

    Have you tried setting the listindex to -1 ?

  3. #3

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: Blanking text of a Dropdown List style ComboBox

    Well pfff. That was WAY too easy. I had envisioned an API call to the text portion of the ComboBox.

    Thanks,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

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