Results 1 to 6 of 6

Thread: Should be easy...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    104
    When the form loads values are loaded into a combobox and a default value is selected from the list.

    cbox.seltext = "Illness Self"

    But when loading the default value into the combobox, the combobox's ListIndex property doesn't get updated to reflect "Illness Self" as being selected. Even though "Illness Self" is set by the SelText property the ListIndex still shows as -1 not 14 which would be the ListIndex for "Illness Self".

    How can I update the ListIndex property when setting a default value for the combobox? It's got to be something easy.

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    quebec
    Posts
    81

    Arrow

    Use the TopIndex property - this shows the correct value for selected item.
    C/C++,Delphi,VB6,Java,PB (blech!),ASP,JSP,SQL...bla bla bla and bla
    I love deadlines. I like the whooshing sound they make as they fly by.
    —Douglas Adams

  3. #3
    Guest
    You can use the Text property to set the text to what you want, which will also highlight the word if it is located in the Combobox.

    Code:
    cbox.Text = "Illness Self"

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    104
    Hitcgar,

    How do I use the TopIndex property?


    Matthew,

    Setting the text property doesn't set the ListIndex to the item that I would set the text to. I need the ListIndex property to reflect the item that is loaded as the default.

    I load the selections from a recordset and set the itemdata property for each item to the primary key id from each record in the set. When adding records to the database I need to access the itemdata property to retrieve the primary key that will be added to the database for the record being added. Illness Self is supposed to be the default value. But when set as the default and I don't touch the combobox I get an error "Invalid property array index" because the ListIndex of the combobox is still set at -1 meaning nothing is selected. I can't retrieve the itemdata property value without a listindex value greater that -1.


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    104
    I figured it out.

    I used the list array and searched for the value and set the listindex.

    Code:
    For i = 0 To cboReason.ListCount - 1
            If cboReason.List(i) = "Illness Self" Then
                cboReason.ListIndex = i
            End If
    Next i

  6. #6
    Lively Member
    Join Date
    Aug 2000
    Location
    quebec
    Posts
    81

    Arrow

    With the TopIndex property you can set the topmost item in the combo to the value you want
    ex.
    Code:
    cb.TopIndex = cb.TopIndex + 5 
        cb.ListIndex = cb.TopIndex
    - causes the list items to scroll 5 items down

    But this is only useful for standard combos (not dropdown) and listboxes.
    C/C++,Delphi,VB6,Java,PB (blech!),ASP,JSP,SQL...bla bla bla and bla
    I love deadlines. I like the whooshing sound they make as they fly by.
    —Douglas Adams

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