Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Listbox Problem

I have a listbox LB and I need to have a sub called when and only when a
line in LB is clicked on.

I am having two problems with LB_Click( ):

1. If I click on the line that is already highlighted, LB_Click is not
called.

2. If my macro changes data in the worksheet from which LB derives its
data then LB_Click( ) is called even though nothing was clicked on.

Is there a way to have a sub that:
will be called EVERY time a line in LB is clicked on
(even in case 1 above)

AND

will not be called UNLESS a line in LB is clicked on
(even in case 2 above)?

Thanks for any help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Listbox Problem

1) as you observe, clicking on an item already selected does not fire the
click event. Perhaps you could have the click event remove the selection so
the box is pristine for the next user selection.

2) break the link between the box and the data. Populate the box with
code.

--

Regards,
Tom Ogilvy

wrote in message
...
I have a listbox LB and I need to have a sub called when and only when a
line in LB is clicked on.

I am having two problems with LB_Click( ):

1. If I click on the line that is already highlighted, LB_Click is not
called.

2. If my macro changes data in the worksheet from which LB derives its
data then LB_Click( ) is called even though nothing was clicked on.

Is there a way to have a sub that:
will be called EVERY time a line in LB is clicked on
(even in case 1 above)

AND

will not be called UNLESS a line in LB is clicked on
(even in case 2 above)?

Thanks for any help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Listbox Problem

Thanks. I'm not sure how to remove the selection. I tried setting the
ListIndex to -1 but that also seemed to fire the click event (of course I
could break the link as you said). Is there a better way to remove the
selection?

I sort of solved the problem by using LB_DblClick, it works exactly as
desired except that it requires the user to double click.

I'm just curious, is there a known reason why Microsoft designed the click
event to work this way

Thanks.

On Thu, 19 Aug 2004 12:23:29 -0400, "Tom Ogilvy" wrote:

1) as you observe, clicking on an item already selected does not fire the
click event. Perhaps you could have the click event remove the selection so
the box is pristine for the next user selection.

2) break the link between the box and the data. Populate the box with
code.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Listbox Problem

You might consider the MouseDown event.

wrote in message
...
Thanks. I'm not sure how to remove the selection. I tried setting the
ListIndex to -1 but that also seemed to fire the click event (of course I
could break the link as you said). Is there a better way to remove the
selection?


You have to disable events if you make changes in code, as described here

http://www.dicks-blog.com/excel/2004...ing_event.html


--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Listbox Problem

I would assume because if someone held down the mouse button while over the
listbox, the click event would fire continuously.

Try adding this to your code: (remove any setting of listindex in the click
event).

Private Sub ListBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ListBox1.ListIndex = -1
End Sub

it seems to allow you to select a selected item and fire the click event
(without firing the click event twice).

--
Regards,
Tom Ogilvy

wrote in message
...
Thanks. I'm not sure how to remove the selection. I tried setting the
ListIndex to -1 but that also seemed to fire the click event (of course I
could break the link as you said). Is there a better way to remove the
selection?

I sort of solved the problem by using LB_DblClick, it works exactly as
desired except that it requires the user to double click.

I'm just curious, is there a known reason why Microsoft designed the click
event to work this way

Thanks.

On Thu, 19 Aug 2004 12:23:29 -0400, "Tom Ogilvy" wrote:

1) as you observe, clicking on an item already selected does not fire

the
click event. Perhaps you could have the click event remove the selection

so
the box is pristine for the next user selection.

2) break the link between the box and the data. Populate the box with
code.






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
Listbox Problem browie Excel Discussion (Misc queries) 5 August 22nd 05 02:03 PM
listbox problem CAA[_11_] Excel Programming 4 January 7th 04 03:27 PM
ListBox problem Mike Fogleman Excel Programming 3 December 29th 03 12:23 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM
Listbox problem Stuart[_5_] Excel Programming 6 August 18th 03 09:14 PM


All times are GMT +1. The time now is 03:06 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"