Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving a control causes the ListBox to deselect the items selected.

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I have a listbox that is the size (width and height) of the Detail section. I have 2 buttons ("Save and Close" "Cancel") located in the Form's footer section. Both the Vertical Anchor property and the Horizontal property of the listbox is set to 2 (both). In the on Resize event of the form, I attempt to keep the buttons centered as the form is resized.

The form's Border Style property is set to "Sizable". When I resize the form by dragging one of the sides of the form with the mouse, the listbox will resize to the size of the form, as expected. If I select, say 3 items, on the listbox and resize the form (i.e. make it wider than narrower by dragging the mouse) the 3 items that were selected eventually become unselected as I'm resizing.

It appears that when I change the horizontal position of the buttons (via the Form_Resize event), the 3 items that were selected become unselected.

Is there something I'm doing wrong? Or is this a bug in Access?

Here's the code in the Form_Resize event
Code:
Private Sub Form_Resize()
    Dim x As Long
    
    x = (Me.InsideWidth / 2) - (((cmdCancel.left + cmdCancel.Width) - cmdOk.left) / 2)
        
    If (x > 0) And (x + (cmdCancel.left - cmdOk.left)) >= (cmdCancel.left - cmdOk.left) Then
        cmdCancel.left = x + (cmdCancel.left - cmdOk.left)
        cmdOk.left = x
    End If
        
    DoEvents
End Sub
 
Don't know as I'd call it a 'bug' so much as simply a behavior exhibited. You're re-arranging the screen's graphics, in the middle of working on a Record (which is a little odd, as most people, wanting a larger Form, would do this before tending to data entry) and a Control whose presentation is dependent on graphics is getting confused!

A possible workaround, in the Form_Resize event, would be to grab the items selected, at the beginning of the event, do the re-sizing, then feed them back into the Listbox at the end of the event.

Linq ;0)>

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
I could have a form with multiple listboxes, textboxes, option groups, and check boxes, from which the user can select items or enter items, on which to filter report(s). Due to a lack of screen realestate, the listboxes may not be sized for optimal entry. When the user clicks a zoom button, a form pops up that contains a list box that becomes a clone of the one on the parent form, including auto selecting items on the pop-up form that matches items selected in the parent form. Since I don't know what the list box contains until runtime, the size of the form, when opened, may not suit the user's needs. Consequently, the user has the ability to resize the form.

I was hoping for a solution that did not involve saving the items selected and then repopulating the list box after the resize has completed. But it appears there is none. So, instead of centering the 2 command buttons, I decided to keep them anchored on the right side of the form.

Thanks for taking the time to respond to my post.

BTW, I worked in Richmond, Va for about 17 years and lived in Chesterfield County. Had a place on Buggs Island lake (Kerr Dam). Nice place to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top