Resize listbox on the fly

Discussion in 'AutoCAD' started by aks01, Aug 3, 2004.

  1. aks01

    aks01 Guest

    Hi, I've asked this question before a few times with no answer and I'm hoping it was because it was not posted through autodesk. Apparently such posts are not visible to most. Now I'm trying again.

    The following is used to resize on the fly both a userform and a listbox within the userform. The idea is to avoid the listbox scroll control. This particular example does not bother to limit the form and listbox height. In AutoCAD VBA the technique works most of the time, but not all of the time. When it fails the userform is the correct new height but the listbox remains at its default height. The listbox always is sized correctly when stepping through the routine in debug mode. The function seems to always function correctly when
    following a file system operation. Repaints do not help.

    Sub SetDlgHeight()
    Dim L As Double
    With ufPickTarget
    L = Max(MinListDepth, .lbFilesOpen.ListCount * 10.2)
    .Height = L + .lbFilesOpen.top + 21
    .lbFilesOpen.Height = L
    End With
    End Sub

    Is there something I can do to force this to function every time?

    thanks, aks
     
    aks01, Aug 3, 2004
    #1
  2. No answers, just questions...

    1 - "When it fails the userform is the correct new height but ..." Do you
    mean that your code runs through with no effect, or does it actually error
    out somewhere?

    2 - Have you compared the values of your variables and control properties on
    runs that work to the runs that fail (using the same list of files), to look
    for differences?

    Sub SetDlgHeight()
    Dim L As Double
    With ufPickTarget
    debug.print "New Run ----------"
    debug.print " MLD = " & minlistdepth & ", ListCount = " &
    ..lbFilesOpen.ListCount
    L = Max(MinListDepth, .lbFilesOpen.ListCount * 10.2)
    debug.print " L calculated = " & L
    debug.print " Form Height Before = " & .height & ", ListBox Top =
    " & .lbFilesOpen.top
    .Height = L + .lbFilesOpen.top + 21
    debug.print " Form Height After = " & .height
    debug.print " Listbox Height Before = " & .lbFilesOpen.Height
    .lbFilesOpen.Height = L
    debug.print " Listbox Height After = " & .lbFilesOpen.Height
    End With
    End Sub

    Good luck,
    James
     
    James Belshan, Aug 7, 2004
    #2
  3. aks01

    aks01 Guest

    1. Yes, the code runs through with no effect.

    2. I usually debug by stepping through at a break point while examining variables as I step to see what happens. The code always works correctly when I do this. Therefore there is nothing to see going wrong. I'll try the debug.print.

    I've used this code in many projects for quite some time with the same problem. I've tried everything I can think of. Sometimes running the code twice in a row works. I'm about to try executing a dummy disk operation system tesk in front of the thing to see if that makes it work every time.

    Perhaps the listbox resize is its own process that does not always execute in time before the form starts waiting for the next event. Once I thought I saw the listbox flash to its correct size just as I closed out the form.
     
    aks01, Aug 8, 2004
    #3
  4. aks01

    aks01 Guest

    Using print.debug proved that the correct height values are passed to the listbox height assignment and that the returned listbox height assignment is in fact the new correct height even though the listbox is clearly remaining unchanged on the screen.

    The times when the listbox height does not change correctly occurs in the init routine. The form's StartUpPosition setting and .left & .top is also changed here to reflect if the form remembers its last position. Moving the listbox resize routine to uccur after that form position change seems to fix the problem.

    So I seem to have a solution without knowing the reason why it works, which probably means the problem will pop up again.
     
    aks01, Aug 9, 2004
    #4
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 (here). After that, you can post your question and our members will help you out.