Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. vb 6.0 combo box delimma

vb 6.0 combo box delimma

Scheduled Pinned Locked Moved Visual Basic
question
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FASTian
    wrote on last edited by
    #1

    well i need to set text for a combo and i dont want anyone else to be able to edit the text. Once some text has been selected the user can also be able to choose an item from the combo meaning i dont want the lock property. I've set the style to 0 and i can do the set text part but it is editable. When i set the combo style property to 2 then i cant set text in the combo. Any ideas what i am missing out on??

    D D 2 Replies Last reply
    0
    • F FASTian

      well i need to set text for a combo and i dont want anyone else to be able to edit the text. Once some text has been selected the user can also be able to choose an item from the combo meaning i dont want the lock property. I've set the style to 0 and i can do the set text part but it is editable. When i set the combo style property to 2 then i cant set text in the combo. Any ideas what i am missing out on??

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I'm confused... What exactly are you trying to do? A ComboBox, style = 2, would let you pick from the list, but not edit the text in the textbox. IIRC, you can set the text in the textbox through code, but only if the text matches an item in the list. So what's the goal here? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      F 1 Reply Last reply
      0
      • D Dave Kreskowiak

        I'm confused... What exactly are you trying to do? A ComboBox, style = 2, would let you pick from the list, but not edit the text in the textbox. IIRC, you can set the text in the textbox through code, but only if the text matches an item in the list. So what's the goal here? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        F Offline
        F Offline
        FASTian
        wrote on last edited by
        #3

        i need to select a particular text and the user should not be able to edit the combo box. Thanks for the reply

        D 1 Reply Last reply
        0
        • F FASTian

          i need to select a particular text and the user should not be able to edit the combo box. Thanks for the reply

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          FASTian wrote: the user should not be able to edit the combo box Then you'll have to make your selection in code and then set the .Enabled property to False. If you let the user make another selection from the dropdown of the combo, that selection will replace any text in the textbox portion of the combo. If you don't want the user to change that text, you either have to disable to combobox or handle the Changed event and, in the event handler, check to see if the .Text property is changed from what it is supposed to be and set it back if necessary. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          • F FASTian

            well i need to set text for a combo and i dont want anyone else to be able to edit the text. Once some text has been selected the user can also be able to choose an item from the combo meaning i dont want the lock property. I've set the style to 0 and i can do the set text part but it is editable. When i set the combo style property to 2 then i cant set text in the combo. Any ideas what i am missing out on??

            D Offline
            D Offline
            Desi Bravo
            wrote on last edited by
            #5

            Your explanation is a bit vague. But using a combo box is easy to construct. No one cannot edit a combo box. I created through a tutorial Customer Orders. This utilizes a combo box with a listing of companies, and updates the customer orders. Also includes a set of dropdown date calendars. These infomation are stored in an access database not sql server. bravo659

            F 1 Reply Last reply
            0
            • D Desi Bravo

              Your explanation is a bit vague. But using a combo box is easy to construct. No one cannot edit a combo box. I created through a tutorial Customer Orders. This utilizes a combo box with a listing of companies, and updates the customer orders. Also includes a set of dropdown date calendars. These infomation are stored in an access database not sql server. bravo659

              F Offline
              F Offline
              FASTian
              wrote on last edited by
              #6

              ok maybe i am explaining this wrong. Here's the actual scenario: 1. We query the server about all the possible city names available and fills the combo box with all the names. Eg. AA,AB,AC and AD 2. When the customer enters a phone number we search the database and if the phone number exists then i just want the combo box to show the city that the matches the phone number for Eg. AB is the city the number matches to then AB should be selected in the combo box. If the number matches no city then we do nothing. 3. We also DONT want the customer to be able to edit the combo box field. 4. The customer can also SELECT a city himself if he wants to by selecting a value from the combo box. anyways thanks for even lookin at this

              E 1 Reply Last reply
              0
              • F FASTian

                ok maybe i am explaining this wrong. Here's the actual scenario: 1. We query the server about all the possible city names available and fills the combo box with all the names. Eg. AA,AB,AC and AD 2. When the customer enters a phone number we search the database and if the phone number exists then i just want the combo box to show the city that the matches the phone number for Eg. AB is the city the number matches to then AB should be selected in the combo box. If the number matches no city then we do nothing. 3. We also DONT want the customer to be able to edit the combo box field. 4. The customer can also SELECT a city himself if he wants to by selecting a value from the combo box. anyways thanks for even lookin at this

                E Offline
                E Offline
                EdbertP
                wrote on last edited by
                #7

                Correct me if I'm wrong, but I think I know what you want: You want to set a specific text into the combobox (from one of the items in the list) through code and you don't want users to edit the combobox text. There are several ways you can do this: 1. Use this function to get and set the index of the item (instead of the text) you want to select in the combobox while keeping your combobox style to 2:

                Public Function GetComboBoxIndex(hWnd As Long, SearchKey As String, Optional FindExactMatch As Boolean = True) As Integer

                'Parameters:
                ' hWnd - the handle to the ComboBox control.  Usage:  Combo1.hWnd
                ' SearchKey - item that you would like to search for.  Can be any string - case doesn't matter when searching
                ' Optional FindExactMatch - Default is True.  Pass False to find a partial match
                'Return:
                ' Returns the index of the found match.  If the match is not found, -1 is returned
                'Usage:
                ' Combo1.ListIndex = GetComboBoxIndex(Combo1.hWnd, "Test Item")
                ' Combo1.ListIndex = GetComboBoxIndex(Combo1.hWnd, "Test Item", False)
                
                If FindExactMatch Then
                    GetComboBoxIndex = CInt(SendMessage(hWnd, CB\_FINDSTRINGEXACT, -1, ByVal SearchKey))
                Else
                    GetComboBoxIndex = CInt(SendMessage(hWnd, CB\_FINDSTRING, -1, ByVal SearchKey))
                End If
                

                End Function

                2. Similar to #1, you can iterate through the combobox item and compare the text to get the index, but this is inefficient. 3. You can implement the AutoFill function on the KeyPress event and IsComboboxItemValid on the Validate event for the combobox. This enables user to type into the combobox (using style 0) but also makes sure that whatever they type will be in the items list.

                Public Sub AutoFillCombobox(ByRef comboBox As comboBox, ByRef KeyAscii As Integer)

                Dim intIndex As Integer
                Dim intRemainder As Integer
                Dim strFullText As String
                Dim strPartialText As String
                
                If comboBox.Locked Then
                    KeyAscii = 0
                    Exit Sub
                End If
                
                If KeyAscii >= 33 And KeyAscii <= 126 Then
                    comboBox.SelText = Chr(KeyAscii)
                    strPartialText = comboBox.Text
                    
                    intIndex = GetComboBoxIndex(comboBox.hWnd, strPartialText, False)
                    If intIndex > -1 Then
                        strFullText = comboBox.List(intIndex)
                        intRemainder = Len(strFullText) - Len(strPartialText)
                        If intRemainder > 0 Then
                            comboBox.SelStart = Len(comboBox.Text)
                            comboBox.SelText = Right(strFullT
                
                F 1 Reply Last reply
                0
                • E EdbertP

                  Correct me if I'm wrong, but I think I know what you want: You want to set a specific text into the combobox (from one of the items in the list) through code and you don't want users to edit the combobox text. There are several ways you can do this: 1. Use this function to get and set the index of the item (instead of the text) you want to select in the combobox while keeping your combobox style to 2:

                  Public Function GetComboBoxIndex(hWnd As Long, SearchKey As String, Optional FindExactMatch As Boolean = True) As Integer

                  'Parameters:
                  ' hWnd - the handle to the ComboBox control.  Usage:  Combo1.hWnd
                  ' SearchKey - item that you would like to search for.  Can be any string - case doesn't matter when searching
                  ' Optional FindExactMatch - Default is True.  Pass False to find a partial match
                  'Return:
                  ' Returns the index of the found match.  If the match is not found, -1 is returned
                  'Usage:
                  ' Combo1.ListIndex = GetComboBoxIndex(Combo1.hWnd, "Test Item")
                  ' Combo1.ListIndex = GetComboBoxIndex(Combo1.hWnd, "Test Item", False)
                  
                  If FindExactMatch Then
                      GetComboBoxIndex = CInt(SendMessage(hWnd, CB\_FINDSTRINGEXACT, -1, ByVal SearchKey))
                  Else
                      GetComboBoxIndex = CInt(SendMessage(hWnd, CB\_FINDSTRING, -1, ByVal SearchKey))
                  End If
                  

                  End Function

                  2. Similar to #1, you can iterate through the combobox item and compare the text to get the index, but this is inefficient. 3. You can implement the AutoFill function on the KeyPress event and IsComboboxItemValid on the Validate event for the combobox. This enables user to type into the combobox (using style 0) but also makes sure that whatever they type will be in the items list.

                  Public Sub AutoFillCombobox(ByRef comboBox As comboBox, ByRef KeyAscii As Integer)

                  Dim intIndex As Integer
                  Dim intRemainder As Integer
                  Dim strFullText As String
                  Dim strPartialText As String
                  
                  If comboBox.Locked Then
                      KeyAscii = 0
                      Exit Sub
                  End If
                  
                  If KeyAscii >= 33 And KeyAscii <= 126 Then
                      comboBox.SelText = Chr(KeyAscii)
                      strPartialText = comboBox.Text
                      
                      intIndex = GetComboBoxIndex(comboBox.hWnd, strPartialText, False)
                      If intIndex > -1 Then
                          strFullText = comboBox.List(intIndex)
                          intRemainder = Len(strFullText) - Len(strPartialText)
                          If intRemainder > 0 Then
                              comboBox.SelStart = Len(comboBox.Text)
                              comboBox.SelText = Right(strFullT
                  
                  F Offline
                  F Offline
                  FASTian
                  wrote on last edited by
                  #8

                  THANKS !! this is what i've been looking for. Sorry guys i guess was being a bit vague in the beginning :-O . anyway the only thing missing is the IsComboboxItemListed(comboBox, intIndex) function and defination CB_FINDSTRINGEXACT i know this is kinda stupid to ask for everything but am a newbie to VB and this is probably the first thing i got stuck on in VB. Thanks for the help dude.. really appreciate it

                  L 1 Reply Last reply
                  0
                  • F FASTian

                    THANKS !! this is what i've been looking for. Sorry guys i guess was being a bit vague in the beginning :-O . anyway the only thing missing is the IsComboboxItemListed(comboBox, intIndex) function and defination CB_FINDSTRINGEXACT i know this is kinda stupid to ask for everything but am a newbie to VB and this is probably the first thing i got stuck on in VB. Thanks for the help dude.. really appreciate it

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    I can't access my PC right now, and this is what I found through Google. If this doesn't work, try searching through Google again. Private Const CB_FINDSTRINGEXACT = &H158 Cheers :-D Edbert P

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups