Results 1 to 8 of 8

Thread: ComboBox(Resolved)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    Resolved ComboBox(Resolved)

    Hi,

    I have a combobox which users can select from options and the records will display in a MSFlexGrid. I set the property to dropdown option 2, so the users are not allow to add or edit in the comboBox. When the user click on the text box, i want the selected option in the comboBox clear but not all the options in the comboBox.

    I have an error saying the field is read only ! when i clear the selected option in the comboBox -
    Private Sub txtBox1_Click()
    comboBox1.Text =""
    ...
    ...
    end sub

    Is there any other way of doing what im tryin to do?
    Last edited by vivian2u; Mar 30th, 2005 at 08:10 AM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: ComboBox

    Try this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Combo1_Click()
    4.   Combo1.RemoveItem Combo1.ListIndex
    5. End Sub
    6.  
    7. Private Sub Form_Load()
    8. Dim x%
    9. For x = 0 To 5
    10.  Combo1.AddItem x
    11.  Next x
    12. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    Re: ComboBox

    Hi
    you are misunderstand my question.

    This is a search options form which user can search the data from 2 different options . They can search by name or month and the selected data will display on a grid. So, I used a comboBox for the month selection and a textBox for keying the name. I set the property to dropdown option 2 for the comboBox , so the users are not allow to add or edit in the comboBox. If the user search the data by selecting the month options, the data for that selected month will display on the grid. If the user continue to search the data by keying the name in the textBox, i want to clear the Grid and clear the selected month in the comboBox when the user key in the textBox.

    But i have an error saying the field is read only !
    How can I clear the selected option in the comboBox??

    Private Sub Form_Load()
    With cbMonth
    .AddItem "January"
    .AddItem "February"
    .AddItem "March"
    .AddItem "April"
    .AddItem "May"
    .AddItem "June"
    .AddItem "July"
    .AddItem "August"
    .AddItem "September"
    .AddItem "October"
    .AddItem "November"
    .AddItem "December"
    End With
    End Sub

    Private Sub cbMonth_Click()
    If cbYear <> "" Then Month (cbMonth.Text)
    End Sub

    Private Sub txtFname_Click()
    cbMonth.Text = ""
    MSFlexGrid1.Clear
    ..
    ..
    End Sub

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ComboBox

    Add a empty string as the first combo item.
    VB Code:
    1. Private Sub Form_Load()
    2. With cboMonth
    3. 'the empty string will be listindex 0
    4. .AddItem "          "
    5. .AddItem "January"
    6. .AddItem "February"
    7. .AddItem "March"
    8. .AddItem "April"
    9. .AddItem "May"
    10. .AddItem "June"
    11. .AddItem "July"
    12. .AddItem "August"
    13. .AddItem "September"
    14. .AddItem "October"
    15. .AddItem "November"
    16. .AddItem "December"
    17. End With
    18. End Sub
    19.  
    20. Private Sub Command1_Click()
    21. cboMonth.ListIndex = 0
    22. MSFlexgrid1.Clear
    23. End Sub

  5. #5
    New Member
    Join Date
    Feb 2004
    Posts
    10

    Thumbs up Re: ComboBox

    there is another short way to avoid adding an extra item in the ComboBox

    Do not add empty string in ComboBox

    Private Sub Form_Load()
    With cboMonth
    .AddItem "January"
    .AddItem "February"
    .AddItem "March"
    .AddItem "April"
    .AddItem "May"
    .AddItem "June"
    .AddItem "July"
    .AddItem "August"
    .AddItem "September"
    .AddItem "October"
    .AddItem "November"
    .AddItem "December"
    End With
    End Sub

    'Set the property of ListIndex to -1
    Private Sub Command1_Click()
    cboMonth.ListIndex = -1
    MSFlexgrid1.Clear
    End Sub

    this is the simple way to do your work no need to add empty string nd its done
    If u dont believe in ur self, Chances are no body else will

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ComboBox

    Quote Originally Posted by canceriens
    there is another short way to avoid adding an extra item in the ComboBox

    Do not add empty string in ComboBox

    Private Sub Form_Load()
    With cboMonth
    .AddItem "January"
    .AddItem "February"
    .AddItem "March"
    .AddItem "April"
    .AddItem "May"
    .AddItem "June"
    .AddItem "July"
    .AddItem "August"
    .AddItem "September"
    .AddItem "October"
    .AddItem "November"
    .AddItem "December"
    End With
    End Sub

    'Set the property of ListIndex to -1
    Private Sub Command1_Click()
    cboMonth.ListIndex = -1
    MSFlexgrid1.Clear
    End Sub

    this is the simple way to do your work no need to add empty string nd its done
    This is a much better solution (and one, quite frankly, I should have thought of!)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    81

    Resolved Re: ComboBox (Resolved)

    Guys,

    Thats exactly what I wanted. Thanks a lot !!


    Vivian

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ComboBox

    Just a note...edit your very first post in this thread and add the check mark and the work "Resolved" to that one. If it is done on the first post of the thread, it will show up in the forum listing.

    Thanks.

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