Results 1 to 11 of 11

Listbox refresh problem -- mysterious phantom highlighting

Threaded View

  1. #1
    Registered User
    Join Date
    10-26-2010
    Location
    Bellevue,WA, USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Listbox refresh problem -- mysterious phantom highlighting

    I'm using Excel2003 VBA, and I have a single-select listbox which, for example, I populate with 4 items:
    listbox1.additem "ITEM 1"
    listbox1.additem "ITEM 2"
    listbox1.additem "ITEM 3"
    listbox1.additem "ITEM 4"

    The listbox1_click event subroutine shows:
    if listbox1 = "ITEM 3" then
    DISPLAY2
    endif

    The DISPLAY2 routine has
    listbox1.clear
    listbox1.listindex = -1 (might be redundant, I think, since I cleared it?)
    listbox1.additem "NEW ITEM 1"
    listbox1.additem "NEW ITEM 2"
    listbox1.additem "NEW ITEM 3"
    listbox1.additem "NEW ITEM 4"

    For some reason, when I select ITEM 3 in the first display, and the second display comes up with the new 4 items, it has NEW ITEM 3 highlighted. I've tried putting the listbox1.listindex = -1 or listbox1.listindex = null below the additem entries, and I've tried changing the listbox1.visible = false before populating it, and listbox1.visible = true after populating it (thinking that a repaint might fix this), but I cannot get it to display the NEW ITEM screen with nothing highlighted. Can you see what I'm doing wrong, or a workaround to this? My best workaround I could think of was to create a listbox2 for the NEW ITEM list, and make the original listbox invisible and the new one visible after I switch, but I don't see why I can't re-use the same listbox, other than this highlighting problem. (It seems to me that it may be detecting a mouse event when it goes to DISPLAY2, and thereby highlighting the area where my mouse is still hovering, but if that's it, I can't think of a way to bypass this situation.) I've also utilized a text box to display the current LISTINDEX value, and strangely, when the macro displays the NEW ITEM list, and it highlights the 3rd item, the listindex displays properly as "-1", although based on what it's highlighting, it should be showing "2".

    Thanks!

    Full Example:
    Private Sub UserForm_Activate()
        Display1
    End Sub
    Private Sub Display1()
        ListBox1.Clear
        ListBox1.AddItem "ITEM 1"
        ListBox1.AddItem "ITEM 2"
        ListBox1.AddItem "ITEM 3"
        ListBox1.AddItem "ITEM 4"
    End Sub
    Private Sub ListBox1_Click()
        Label1 = ListBox1
        If ListBox1 = "ITEM 3" Then
            Display2
        End If
    End Sub
    Private Sub Display2()
        ListBox1.Clear
        ListBox1.AddItem "NEW ITEM 1"
        ListBox1.AddItem "NEW ITEM 2"
        ListBox1.AddItem "NEW ITEM 3" (this item is highlighted automatically when I selected ITEM 3)
        ListBox1.AddItem "NEW ITEM 4"
    End Sub
    Last edited by RexKatWa; 10-26-2010 at 09:41 PM. Reason: Added Code Tags

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