|
-
Mar 30th, 2005, 04:22 AM
#1
Thread Starter
Lively Member
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.
-
Mar 30th, 2005, 04:25 AM
#2
Re: ComboBox
Try this:
VB Code:
Option Explicit
Private Sub Combo1_Click()
Combo1.RemoveItem Combo1.ListIndex
End Sub
Private Sub Form_Load()
Dim x%
For x = 0 To 5
Combo1.AddItem x
Next x
End Sub
-
Mar 30th, 2005, 04:58 AM
#3
Thread Starter
Lively Member
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
-
Mar 30th, 2005, 06:42 AM
#4
Re: ComboBox
Add a empty string as the first combo item.
VB Code:
Private Sub Form_Load()
With cboMonth
'the empty string will be listindex 0
.AddItem " "
.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 Command1_Click()
cboMonth.ListIndex = 0
MSFlexgrid1.Clear
End Sub
-
Mar 30th, 2005, 07:36 AM
#5
New Member
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
-
Mar 30th, 2005, 07:46 AM
#6
Re: ComboBox
 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!)
-
Mar 30th, 2005, 08:05 AM
#7
Thread Starter
Lively Member
-
Mar 30th, 2005, 08:08 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|