PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
combo box select-VBForums
Results 1 to 20 of 20

Thread: combo box select

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    combo box select

    hi, im having problem on combo box..

    my code is:

    VB Code:
    1. Private Sub form_load()
    2. With combo1
    3.     .AddItem "test1"
    4.     .AddItem "test"
    5. End With
    6. End Sub

    the combo style is Dropdown list.. what should i do when the program runs and display test1 on combo automatically? for me i did like this

    VB Code:
    1. Private Sub form_load()
    2. With combo1
    3.     .AddItem "test1"
    4.     .AddItem "test"
    5. End With
    6. combo1.text = "test"
    7. End Sub

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: combo box select

    Use ListIndex.

    Like Combo1.ListIndex = 1

    EDIT: In your method, you are adding text "Text" to the Combo, NOT selecting a List Item!
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  3. #3
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: combo box select

    Use,
    VB Code:
    1. [b]Combo1.ListIndex = 0[/b] ' -1 to unselect all

    Also, in dropdownlist style, Cobmo1_Change event will not fire. You'll need to use the Combo1_Click event instead.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    Re: combo box select

    VB Code:
    1. Private Sub form_load()
    2. With combo1
    3.     .listindex = 1
    4.     .AddItem "test1"
    5.     .AddItem "test"
    6. End With
    7. End Sub

    i did like this but i got an error

  5. #5
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: combo box select

    VB Code:
    1. Private Sub form_load()
    2. With combo1
    3.     .AddItem "test1"
    4.     .AddItem "test"
    5.     [hl].listindex = 1[/hl]
    6. End With
    7. End Sub
    Just note that setting ListIndex = 1, the default in your combobox will be test. ListIndex = 0 would be test1

  6. #6
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: combo box select

    by the way, youre getting the error because youre setting the item in the comboxbox before you set the items. setting the default when there isnt anything to set is what caused your error

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: combo box select

    Quote Originally Posted by nokmaster
    i did like this but i got an error
    The error is because you tried to set the ListIndex of the Combo PRIOR to there being any items loaded - BrailleSchool has highlited the correction.
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  8. #8
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: combo box select

    This thread got me thinking, suppose I have values in a combobox which are from a recordset, how can I set a default value from any of the items and not necessarily the first one?

  9. #9
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: combo box select

    Quote Originally Posted by osemollie
    This thread got me thinking, suppose I have values in a combobox which are from a recordset, how can I set a default value from any of the items and not necessarily the first one?
    you set it ListIndex. a combobox is zero based. meaning this:

    Item1 is ListIndex = 0
    Item2 is ListIndex = 1
    Item3 is ListIndex = 2
    Item4 is ListIndex = 3
    Item5 is ListIndex = 4
    Item6 is ListIndex = 5
    .........

  10. #10
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: combo box select

    If I set the ListIndex = 1 (or any other number) I get an error
    " Run time error 380. Invalid property value"

    But if I leave it at ListIndex = 0, it works fine and there is NO error. However, ListIndex = 0 is the first entry in the table BUT I want the default to be another value that is not necessarily the 1st entry.

    Thanks

  11. #11
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: combo box select

    osemollie,

    In the example you have tried, what is the rusult of you adding this to your code:

    MsgBox List1.ListCount
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  12. #12
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: combo box select

    The ListCount is 7

    Thanks

  13. #13
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: combo box select

    Any idea why am getting an error?

  14. #14
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: combo box select

    Quote Originally Posted by osemollie
    The ListCount is 7

    Thanks
    Therefore you shuld have 8 choices (excluding-1) a range from 0-7!

    Post the code block that loads your ListBox (and what you had used to set the ListIndex).
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  15. #15
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: combo box select

    The code is:-
    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.  
    4. Set cnAddMovie = New ADODB.Connection
    5. cnAddMovie.Provider = "Microsoft.Jet.OLEDB.4.0"
    6. cnAddMovie.Open App.Path & "./databases/visualtek.mdb"
    7.  
    8. Set rsMovie = New ADODB.Recordset
    9. 'Add ComboBox
    10. Dim strSQL As String    'Declare the variables we need
    11.                
    12.     strSQL = "SELECT UserNo, (FirstName+' '+LastName) As Name FROM users ORDER BY FirstName"
    13.  
    14.     rsMovie.Open strSQL, cnAddMovie, adOpenForwardOnly, adLockReadOnly, adCmdText
    15.                            
    16.   With cboPatron
    17.     .Clear
    18.     Do While Not rsMovie.EOF
    19.       .AddItem rsMovie.Fields("Name").Value
    20.       .ItemData(.NewIndex) = rsMovie.Fields("UserNo").Value
    21.         .ListIndex = 3
    22.       rsMovie.MoveNext
    23.     Loop
    24.    
    25.   End With
    26.  
    27.   rsMovie.Close
    28.   Set rsMovie = Nothing

  16. #16
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: combo box select

    Got it, I had placed my ListIndex inside the loop. I have now removed it from the loop and it now works!!!

    Thanks Bruce Fox for your patience and nokmaster for starting the thread.

  17. #17
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,680

    Re: combo box select

    Quote Originally Posted by Bruce Fox
    Therefore you shuld have 8 choices (excluding-1) a range from 0-7!

    Post the code block that loads your ListBox (and what you had used to set the ListIndex).
    Are you sure about that? If the listcount is 7.... then wouldn't the possible ListIndexes run from 0 to 6???

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  18. #18
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: combo box select

    Quote Originally Posted by techgnome
    Are you sure about that? If the listcount is 7.... then wouldn't the possible ListIndexes run from 0 to 6???

    -tg

  19. #19
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425

    Re: combo box select

    Quote Originally Posted by techgnome
    Are you sure about that? If the listcount is 7.... then wouldn't the possible ListIndexes run from 0 to 6???

    -tg
    Doh. I never said I could count past 5

    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

  20. #20
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: combo box select

    Quote Originally Posted by Bruce Fox
    Doh. I never said I could count past 5

    i cant even count up to 5, had to get help from my 4 year old lol

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width