+ Reply to Thread
Results 1 to 4 of 4

Listboxes and changing colors

  1. #1
    Registered User
    Join Date
    01-07-2006
    Posts
    18

    Listboxes and changing colors

    I've just experienced an anoying item for which I can't seem to find a solution other then completely reprogramming a certain routine.

    In listboxes with multiple items selected, when you change the front or back color all items selected are de-selected. I can't find any comments in the VBA books I have or Excel help. I also tried finding something similar on this forum but to no avail.

    Is there a solution for this anoying effect? Is there anybody whom might be able to shed some light on this?

    Thanks in advance for any ideas.

    Leon

  2. #2
    Dave Peterson
    Guest

    Re: Listboxes and changing colors

    I've never noticed this, but I don't think I've ever changed the font <bg>.

    Maybe you could just keep track of what was selected before you do your stuff.
    I build a userform with a listbox and a couple of buttons. This seemed to work
    ok.

    Option Explicit
    Private Sub CommandButton1_Click()
    Dim mySelected() As Boolean
    Dim iCtr As Long
    Dim TopItem As Long

    With Me.ListBox1
    TopItem = .TopIndex

    ReDim mySelected(0 To .ListCount - 1)

    For iCtr = 0 To .ListCount - 1
    mySelected(iCtr) = .Selected(iCtr)
    Next iCtr

    If .Font.Name = "Arial" Then
    .Font.Name = "Courier New"
    Else
    .Font.Name = "Arial"
    End If

    For iCtr = 0 To .ListCount - 1
    .Selected(iCtr) = mySelected(iCtr)
    Next iCtr

    .TopIndex = TopItem
    End With
    End Sub
    Private Sub CommandButton2_Click()
    Unload Me
    End Sub
    Private Sub UserForm_Initialize()
    Dim iCtr As Long
    With Me.ListBox1
    .MultiSelect = fmMultiSelectMulti
    For iCtr = 1 To 10
    .AddItem "asdf" & iCtr
    Next iCtr
    End With
    End Sub


    droopy928gt wrote:
    >
    > I've just experienced an anoying item for which I can't seem to find a
    > solution other then completely reprogramming a certain routine.
    >
    > In listboxes with multiple items selected, when you change the front or
    > back color all items selected are de-selected. I can't find any
    > comments in the VBA books I have or Excel help. I also tried finding
    > something similar on this forum but to no avail.
    >
    > Is there a solution for this anoying effect? Is there anybody whom
    > might be able to shed some light on this?
    >
    > Thanks in advance for any ideas.
    >
    > Leon
    >
    > --
    > droopy928gt
    > ------------------------------------------------------------------------
    > droopy928gt's Profile: http://www.excelforum.com/member.php...o&userid=30232
    > View this thread: http://www.excelforum.com/showthread...hreadid=528965


    --

    Dave Peterson

  3. #3
    Registered User
    Join Date
    01-07-2006
    Posts
    18
    Hi Dave,

    Thanks for the reply. What you suggest is indeed what I meant with reprogramming a certain routine.

    I'd never noticed it either but due to a window being used for multiple purposes I thought to be smart and change the back ground color for the item selected so the user would immediatly see where he was in that window. Normally this is no issue at all but with listboxes where items are selected the selected items are lost and need to be reselected which is annoying ofcourse.

    Best regards,

    Leon v/d Willik

  4. #4
    Dave Peterson
    Guest

    Re: Listboxes and changing colors

    I'm not quite sure what you're doing (and I didn't test this, either)...

    But maybe you could have two listboxes--one visible and one hidden. Then
    hide/show the ones you want.

    droopy928gt wrote:
    >
    > Hi Dave,
    >
    > Thanks for the reply. What you suggest is indeed what I meant with
    > reprogramming a certain routine.
    >
    > I'd never noticed it either but due to a window being used for multiple
    > purposes I thought to be smart and change the back ground color for the
    > item selected so the user would immediatly see where he was in that
    > window. Normally this is no issue at all but with listboxes where
    > items are selected the selected items are lost and need to be
    > reselected which is annoying ofcourse.
    >
    > Best regards,
    >
    > Leon v/d Willik
    >
    > --
    > droopy928gt
    > ------------------------------------------------------------------------
    > droopy928gt's Profile: http://www.excelforum.com/member.php...o&userid=30232
    > View this thread: http://www.excelforum.com/showthread...hreadid=528965


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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