Results 1 to 5 of 5

Thread: combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    7

    combobox

    Hello.

    How can I select an option of a combobox dynamicaly?

    sort of comboBox1.selectItem(5);

    and how can I make the combobox not editabe?... that is... the user can use the combobox for choosing the available options, but not to enter new text


    thanks

  2. #2
    Junior Member Shattered's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    26

    Re: combobox

    Originally posted by pilsjart
    How can I select an option of a combobox dynamicaly?

    sort of comboBox1.selectItem(5);
    Sheet1.ComboBox1.ListIndex = iVal

    where iVal is the number you want to select, so in your example iVal could be replaced with 5

    and how can I make the combobox not editabe?... that is... the user can use the combobox for choosing the available options, but not to enter new text
    Private Sub ComboBox1_Change()
    If Sheet1.ComboBox1.ListIndex = -1 Then Sheet1.ComboBox1.Text = ""
    End Sub

    basically if new text is entered it won't be found in the combo box and will therefore have an index value of -1, when this happpens just clear the box..

    Simple but effective
    "much to learn you still have"

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    7
    thanks...

    about the:

    Private Sub ComboBox1_Change()
    If ComboBox1.ListIndex = -1 Then ComboBox1.Text = ""
    End Sub

    can It simply remain in the same ListIndex position?

    that is, when I type any text, I want the comboBox to remain in te same selection without moving to the position -1.

    Is it possible?

  4. #4
    Junior Member Shattered's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    26
    it is possible but basically it would require you to store the value of the current index and only change the index value when the current value is greater than -1

    -1 basically shows that no item is selected.
    "much to learn you still have"

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    If you don't want the user to be able to edit/add items, set the dropdownstyle to dropdownlist (Think this works in VBA, it's in VB, anyway. Hard to keep the differences between VBA, VB6 and VB.Net separate sometimes).

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