+ Reply to Thread
Results 1 to 7 of 7

Cannot set Listindex property!

  1. #1
    Registered User
    Join Date
    09-03-2007
    Posts
    51

    Cannot set Listindex property!

    For some reason my selection won't return to where it's supposed to in a listbox after I've increased it's column widths. It's very strange.

    I've put together an example of the issue as the actual workbook is enormous, but the demonstration seems to work.

    I've tried exporting the Listindex resetting code to an external function, but it didn't help either.

    Can anyone understand this behaviour?

    Thanks very much for the consideration!

    - Gordon
    Attached Files Attached Files
    Last edited by Gordon@work; 11-06-2008 at 05:48 PM. Reason: Solved by Leith of course!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Gordon,

    The ListBox responds to clicking a row by highlighting it. The ListIndex property is updated to reflect the row or rows selected. However, the reverse doesn't hold true. When the ListBox's dimensions are changed externally, it is redrawn. The highlighting only occurs because a system message has been sent to the ListBox window telling it the user has clicked the mouse over it. There are ways to do this using the Windows API, but it quite complicated to do and probably not worth the effort for the effect. Unfortunately, I don't know of any workaround to accomplish this.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    09-03-2007
    Posts
    51
    Quote Originally Posted by Leith Ross View Post
    Hello Gordon,
    Hello Leith, thanks for lending your intellect to my problems again!

    The ListBox responds to clicking a row by highlighting it. The ListIndex property is updated to reflect the row or rows selected. However, the reverse doesn't hold true.
    I don't really understand what you mean here - I've never had a problem setting the ListIndex property to the row I need selected before.
    When the ListBox's dimensions are changed externally, it is redrawn. The highlighting only occurs because a system message has been sent to the ListBox window telling it the user has clicked the mouse over it.
    I can make it highlight the correct row again with a simple commandbutton-driven event that specifies the listindex, but not in the same scrollbar event or a function run from it.
    There are ways to do this using the Windows API, but it quite complicated to do and probably not worth the effort for the effect. Unfortunately, I don't know of any workaround to accomplish this.
    I couldn't find a workaround either. I've tried every combination of listbox1.setfocus:sendkeys({"LEFT"}) and _afterupdate.

    I've done some limited work with API and I'd be more than willing to try to hack a solution together if you have a possible method in mind, although I'm not sure how to find the classid or handle of a listbox... only windows.

    Did the method you were considering involve sendmessaging LB_SETCURSEL, ListPos to the control's handle?
    Sincerely,
    Leith Ross
    Thanks you very much!

    - Gordon

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Gordon,

    You sound like you really want to pursue this. So, I guess we both take the red pill and see how far down the rabbit hole goes. I will have to do some review and write some test code. After that, I can go over it with you. Hopefully we won't blow any computer up in process.

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    09-03-2007
    Posts
    51
    Wicked Leith, that would be excellent!

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,419
    This works for me.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  7. #7
    Registered User
    Join Date
    09-03-2007
    Posts
    51
    Oh Leith!
    I didn't think of the .Selected property, but it works ideally!
    I don't know how to thank you enough. I'll share this project with you when it's stable and I'm sure you'll appreciate the difference those two lines of code actually make.

    Thank you so much!

    - Gordon

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1