ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Listboxes and changing colors (https://www.excelbanter.com/excel-programming/357785-listboxes-changing-colors.html)

droopy928gt[_8_]

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


--
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

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

droopy928gt[_9_]

Listboxes and changing colors
 

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

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


All times are GMT +1. The time now is 12:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com