Results 1 to 1 of 1

Thread: Display the drop down list of Combo box Explicitly

  1. #1

    Thread Starter
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Display the drop down list of Combo box Explicitly

    When you set the DropDownStyle property of Combo box, it allows you input the text like text box control. When you type something and press down arrow key then the item from the list which starts from the text entered is selected. Imagine, how helpful it would be if we can see the drop down list while typing. Below is the code which does exactly the same.

    In this code I am displaying the drop down list on GotFocus event of ComboBox.

    vb.net Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Public Class Form1
    4.  
    5.     <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    6.     Private Shared Function SendMessage( _
    7.         ByVal hWnd As IntPtr, _
    8.         ByVal Msg As UInteger, _
    9.         ByVal wParam As IntPtr, _
    10.         ByVal lParam As IntPtr) As IntPtr
    11.     End Function
    12.  
    13.     Public Const CB_SHOWDROPDOWN As Long = &H14F
    14.  
    15.     Private Sub Form1_Load( _
    16.         ByVal sender As System.Object, _
    17.         ByVal e As System.EventArgs _
    18.     ) Handles MyBase.Load
    19.  
    20.         Dim comboItems() As String
    21.         comboItems = New String() {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}
    22.  
    23.         With ComboBox1
    24.             .Items.Clear()
    25.             .Items.AddRange(comboItems)
    26.         End With
    27.     End Sub
    28.  
    29.     Private Sub ComboBox1_GotFocus( _
    30.         ByVal sender As Object, _
    31.         ByVal e As System.EventArgs _
    32.     ) Handles ComboBox1.GotFocus
    33.  
    34.         Dim iret As IntPtr
    35.         iret = SendMessage(ComboBox1.Handle, CB_SHOWDROPDOWN, New IntPtr(CInt(True)), IntPtr.Zero)
    36.     End Sub
    37.  
    38. End Class

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