Resetting a listbox value and scrolled position

G

Guest

Hi all,

I'm working on implementing a 'Reset' button on my form. All the controls
on the form reset properly, but I can't find a way to reset the scrolled to
position of a listbox.

To reset the listbox I've used lstItem.Value = 0

This works to clear all the selected items in the list. However, the scroll
position does not change. I'd like to set the position of the scroll bar
back to the top when I reset the form.

If anyone has any idea how I can do this, I'd appreciate it.

Also (as a bonus question) if anyone knows how to autosize column widths in
a list box, pass it on. I'm using A97 and it's not a property.

Thanks,
Jay
 
G

Guest

Requery the list box. It will clear any selections made and position it back
to the first entry in the list.

Me.MyListBox.Requery

I don't believe there is any way to "autosize" columns in a list box. You
can programmatically set the column widths using the columnwidths property.
 
G

Guest

Klatuu,

It doesn't work. The selection and position in list box remains unchanged.

Would the fact I'm using A97 matter?

Jay

(I accidentally hit the button saying it answered the question).
 
G

Guest

I don't know. I haven't worked in 97 since about 1999. I don't see why it
should. Is yours a single select or a multi select list box? I tested this
 
G

Guest

Yes, it's a multi select listbox.

The Requery does clear al selected items from the list, but the listbox
doesn't return back to the top of the listbox. So if I scroll to the bottom
and use Requery, the item is no longer selected, but the litbox is still at
the bottom.

Thanks for your help though.

Jay
 
G

Guest

Klatuu,

That's awesome, thanks! Works perfectly.

I don't know how you managed to find that. I'm glad I posted because I
never would have tried that. Excellent work!

Jay
 
G

Guest

Thanks for the Kudos.
All I did was open the Object Browser and start looking at all the
properties and methods of a List Box and think about what they will do. When
I go to the Height property, it dawned on me I had a form where 8 list boxes
start with a height of 0 and are only resized when the user clicks a command
button. Then I played with it and realized that every time I reopened one of
the list boxes that had enough entries to require a scroll bar, it was always
positioned at the top when I resized it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top