Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default Selected... or not ??

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 ? :)
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default Selected... or not ??

On Wed, 03 Jun 2009 21:08:13 -0500, Dave Peterson
wrote:
Hi Dave,

Thanks for that suggestion. I spent several hours
playing around... it showed the Change event was fired
more than once, and that my List Enter and Userform
Initialise code wasn'tt running every time. I can't fathom why
things work differently with a temp STOP command, than without one.

Anyway, I moved the form Initialise and List enter stuff into a
module, so I know it's runs once, reliably.

This produced a marqee-only every time, but the following
Selects it -

Private Sub List1_Enter()

Me.List1.Selected(0)) = False
Me.List1.Selected(0) = True

Exit Sub

Doesn't make sense to me... but this seems to do the trick

Thanks - Kirk
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Selected... or not ??

Or you could have tried using a boolean variable to exit the event you don't
want as soon as it starts.

kirkm wrote:

On Wed, 03 Jun 2009 21:08:13 -0500, Dave Peterson
wrote:
Hi Dave,

Thanks for that suggestion. I spent several hours
playing around... it showed the Change event was fired
more than once, and that my List Enter and Userform
Initialise code wasn'tt running every time. I can't fathom why
things work differently with a temp STOP command, than without one.

Anyway, I moved the form Initialise and List enter stuff into a
module, so I know it's runs once, reliably.

This produced a marqee-only every time, but the following
Selects it -

Private Sub List1_Enter()

Me.List1.Selected(0)) = False
Me.List1.Selected(0) = True

Exit Sub

Doesn't make sense to me... but this seems to do the trick

Thanks - Kirk


--

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

Or you could have tried using a boolean variable to exit the event you don't
want as soon as it starts.

kirkm wrote:

On Wed, 03 Jun 2009 21:08:13 -0500, Dave Peterson
wrote:
Hi Dave,

Thanks for that suggestion. I spent several hours
playing around... it showed the Change event was fired
more than once, and that my List Enter and Userform
Initialise code wasn'tt running every time. I can't fathom why
things work differently with a temp STOP command, than without one.

Anyway, I moved the form Initialise and List enter stuff into a
module, so I know it's runs once, reliably.

This produced a marqee-only every time, but the following
Selects it -

Private Sub List1_Enter()

Me.List1.Selected(0)) = False
Me.List1.Selected(0) = True

Exit Sub

Doesn't make sense to me... but this seems to do the trick

Thanks - Kirk


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default Selected... or not ??

On Wed, 03 Jun 2009 21:08:13 -0500, Dave Peterson
wrote:
Hi Dave,

Thanks for that suggestion. I spent several hours
playing around... it showed the Change event was fired
more than once, and that my List Enter and Userform
Initialise code wasn'tt running every time. I can't fathom why
things work differently with a temp STOP command, than without one.

Anyway, I moved the form Initialise and List enter stuff into a
module, so I know it's runs once, reliably.

This produced a marqee-only every time, but the following
Selects it -

Private Sub List1_Enter()

Me.List1.Selected(0)) = False
Me.List1.Selected(0) = True

Exit Sub

Doesn't make sense to me... but this seems to do the trick

Thanks - Kirk
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Selected... or not ??

any time you click an item in a listbox control, the change event fires.
when an item is selected using the SELECTED property, it also fires the
change event. The change event will fire even if the item state doesn't
change

so
listbox1.selected(5)=True
listbox1.selected(5)=True
will fire twice even though the 2nd line doesn't change the property value.
imagine it like the worksheet change event. it will fire if you type A into
a cell. it will fire again if you type A into the same cell


for a multiselect you test if an item is selected

with listbox1
for i = 0 to .listcount-1 'zero based
if .selected(i) then
'item i is selected
end if
next
end with

an item is selected by using this code
listbox1.selected(index)=True
and deselected by
listbox1.selected(index)=False


"kirkm" wrote in message ...
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 ? :)


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default Selected... or not ??

On Thu, 4 Jun 2009 09:46:11 +0100, "Patrick Molloy"
wrote:

Thanks for the rundown. Learning more all the time.. ceratinly all
this multiple firing and what's called and in what sequencecan be hard
to follow. By the waycould you explain what 'Control Source' is in
relation to a listbox, please?
Not the Excel help, which I can't fathom, but in normal English? :)

Thanks... there was another thread but it went cold, and there
was no answer.
Cheers - Kirk



any time you click an item in a listbox control, the change event fires.
when an item is selected using the SELECTED property, it also fires the
change event. The change event will fire even if the item state doesn't
change

so
listbox1.selected(5)=True
listbox1.selected(5)=True
will fire twice even though the 2nd line doesn't change the property value.
imagine it like the worksheet change event. it will fire if you type A into
a cell. it will fire again if you type A into the same cell


for a multiselect you test if an item is selected

with listbox1
for i = 0 to .listcount-1 'zero based
if .selected(i) then
'item i is selected
end if
next
end with

an item is selected by using this code
listbox1.selected(index)=True
and deselected by
listbox1.selected(index)=False

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default Selected... or not ??

On Thu, 4 Jun 2009 09:46:11 +0100, "Patrick Molloy"
wrote:

Thanks for the rundown. Learning more all the time.. ceratinly all
this multiple firing and what's called and in what sequencecan be hard
to follow. By the waycould you explain what 'Control Source' is in
relation to a listbox, please?
Not the Excel help, which I can't fathom, but in normal English? :)

Thanks... there was another thread but it went cold, and there
was no answer.
Cheers - Kirk



any time you click an item in a listbox control, the change event fires.
when an item is selected using the SELECTED property, it also fires the
change event. The change event will fire even if the item state doesn't
change

so
listbox1.selected(5)=True
listbox1.selected(5)=True
will fire twice even though the 2nd line doesn't change the property value.
imagine it like the worksheet change event. it will fire if you type A into
a cell. it will fire again if you type A into the same cell


for a multiselect you test if an item is selected

with listbox1
for i = 0 to .listcount-1 'zero based
if .selected(i) then
'item i is selected
end if
next
end with

an item is selected by using this code
listbox1.selected(index)=True
and deselected by
listbox1.selected(index)=False

  #10   Report Post  
Posted to microsoft.public.excel.programming
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


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Selected... or not ??

any time you click an item in a listbox control, the change event fires.
when an item is selected using the SELECTED property, it also fires the
change event. The change event will fire even if the item state doesn't
change

so
listbox1.selected(5)=True
listbox1.selected(5)=True
will fire twice even though the 2nd line doesn't change the property value.
imagine it like the worksheet change event. it will fire if you type A into
a cell. it will fire again if you type A into the same cell


for a multiselect you test if an item is selected

with listbox1
for i = 0 to .listcount-1 'zero based
if .selected(i) then
'item i is selected
end if
next
end with

an item is selected by using this code
listbox1.selected(index)=True
and deselected by
listbox1.selected(index)=False


"kirkm" wrote in message ...
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 ? :)


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple cells or columns are selected instead of selected cell or Mikey Excel Discussion (Misc queries) 1 April 29th 09 09:48 PM
Cells are selected but aren't displayed as selected Nifty Excel Discussion (Misc queries) 2 September 17th 06 07:22 PM
Cells are selected but aren't displayed as selected Nifty Excel Worksheet Functions 0 September 17th 06 11:34 AM
Macro to take selected cells times a selected cell Craig Excel Programming 4 October 24th 05 12:54 AM
how do i make it so that when a sheat is selected either via link or tab, that xlLastCell is selected. the last on the sheet. Daniel Excel Worksheet Functions 1 July 12th 05 01:30 AM


All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"