List Box

pjfatboy
09-11-2003, 09:37 AM
On one of the forms in my project I have a Dropdown List Box. When the user clicks a button to pass some information to another part of the form I would like for the list box to clear along with the text boxs on the form. I can get the text boxes to clear but the list box gives me an error saying that it is a read only. I tried this but that didn't work. Does anyone know how to cause the list box to show nothing on command.

Repcmb.AddItem " "

Repcmb = " "

Flyguy
09-11-2003, 09:38 AM
List1.Clear

pjfatboy
09-11-2003, 09:40 AM
List1.Clear

Thanks Flyguy

pjfatboy
09-11-2003, 09:43 AM
List1.Clear

Thanks Flyguy

Flyguy that cleared the list but when I tried to use the list again the list was gone. I had to close the form and reopen it again to get the list to repopulate.

nsmoller
09-11-2003, 09:46 AM
you need to either put a blank entry into your listbox with an index of 0 and then in the clear section put list.index=0 or whatever
or
just list1.text="" (i think this only works for comboboxes)

pjfatboy
09-11-2003, 09:47 AM
you need to either put a blank entry into your listbox with an index of 0 and then in the clear section put list.index=0 or whatever
or
just list1.text="" (i think this only works for comboboxes)

Yes, I can get the combo box to clear on the same form but this list box is the one I'm having trouble with.

matstuff
09-11-2003, 09:51 AM
If you've got a combobox then it depends on the style. If it's a dropdown list you can't assign it's text property, so you need to have a blank value in there and then set the listindex to equal that of the blank value. You can add and remove the blank value on the fly if you don't want it to appear there all the time.

Alternatively, if it's a dropdown combo you can assign the text property. If you do it this way, you just need to validate that what the user has put in is ok.

pjfatboy
09-11-2003, 09:54 AM
If you've got a combobox then it depends on the style. If it's a dropdown list you can't assign it's text property, so you need to have a blank value in there and then set the listindex to equal that of the blank value. You can add and remove the blank value on the fly if you don't want it to appear there all the time.

Alternatively, if it's a dropdown combo you can assign the text property. If you do it this way, you just need to validate that what the user has put in is ok.


How do I set the listindex to equal that of the blank value?

pjfatboy
09-11-2003, 09:56 AM
If you've got a combobox then it depends on the style. If it's a dropdown list you can't assign it's text property, so you need to have a blank value in there and then set the listindex to equal that of the blank value. You can add and remove the blank value on the fly if you don't want it to appear there all the time.

Alternatively, if it's a dropdown combo you can assign the text property. If you do it this way, you just need to validate that what the user has put in is ok.


How do I set the listindex to equal that of the blank value?

Agent707
09-11-2003, 09:56 AM
Sounds like you have list items coded into the list box at design time. Bad idea if it's not a static list box (which in this case it's not).

You need to write a routine to populate the listbox

For i = 0 to howmanyitems
listbox.additem yourdata
Next

Then just call that routine to re-populate the listbox when you need to.

Something like that.

nsmoller
09-11-2003, 09:56 AM
correct me if i'm wrong

private sub clear_dat_smack()
dim iNum as integer
iNum=list1.count 'gets number of items
list1.additem " "
list1.listindex=iNum 'since indexes include 0 and this is supposed
' to be 1 more, then index of new item = count before add
end sub

pjfatboy
09-11-2003, 09:58 AM
Sounds like you have list items coded into the list box at design time. Bad idea if it's not a static list box (which in this case it's not).

You need to write a routine to populate the listbox

For i = 0 to howmanyitems
listbox.additem yourdata
Next

Then just call that routine to re-populate the listbox when you need to.

Something like that.

Ok, that makes since. Thanks

Flyguy
09-11-2003, 10:06 AM
Sorry I misunderstood your question.
If you set .ListIndex = -1 then NO item should be selected.

reboot
09-11-2003, 10:08 AM
If you're trying to remove a particular item from the listbox, use the RemoveItem method.

pjfatboy
09-11-2003, 10:09 AM
Sorry I misunderstood your question.
If you set .ListIndex = -1 then NO item should be selected.

Thanks guys, I got to work.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum