View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Selected... or not ??

I bet you have some other code that's running when you change that .selected(0)
to true. Look for the list_change event.

In fact, if you can step through the code, you may see it walk to a procedure
that you didn't realize was firing.

If I'm correct, you can do this kind of thing:

Option Explicit
Dim BlkProc As Boolean
Private Sub CommandButton1_Click()
BlkProc = True
Me.ListBox1.Selected(0) = True
BlkProc = False
End Sub
Private Sub ListBox1_Change()
If BlkProc = True Then Exit Sub
'your code here
MsgBox "hi from _change"
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.AddItem "A"
.AddItem "B"
.AddItem "C"
End With
End Sub

The BlkProc variable (and the check if it's true) serves the same kind of
purpose as "Application.enableevents = false" in a worksheet event.

Try uncommenting the "if blkproc = true" statement and you'll see that the
_change event will fire if the user changes the listbox--or if your code changes
it.


kirkm wrote:

What's the group consider the definition of Selected ?

Here's Excel help...

--
object.Selected( index ) [= Boolean]

The Selected property syntax has these parts:

Part Description
object Required. A valid object.
index Required. An integer with a range from 0 to one less than the
number of items in the list.
Boolean Optional. Whether an item is selected.

Settings

The settings for Boolean a

Value Description
True The item is selected.
False The item is not selected.
--

So, this command

frmTest.List1.Selected(0) = True

Should select line1 in a listbox?

Well I supoose (as it does) to put a marqee around the line does
'Select' it but
changing the command to = False additionally highlights the line.

Which surely means, THEN it's selected ? Or is my Excel working in
reverse ? :)


--

Dave Peterson