It is currently Sat May 25, 2013 12:05 pm

All times are UTC





Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Refreshing ListBox
PostPosted: Tue Aug 07, 2012 8:55 pm 
Offline
Forum Admin
User avatar

Joined: 29 Jan 2004
Posts: 13448
Country: United States
State: Florida
CAD System: Inventor
I have a ListBox in an Excel VBA form that is poplated by a named range:

Code:
Private Sub UserForm_Activate()

ListBox1.RowSource = Range("Pneumatics").Address

End Sub


When the user selects a value I want to refresh the listbox values with new values...

Code:
Private Sub ListBox1_Click()

Select Case ListBox1.ListIndex

Case 0
ListBox1.ListIndex = -1 'deselect the selected value
ListBox1.RowSource = "" ' clear the list
ListBox1.RowSource = Range("Frames").Address ' repopulate the list
Case 1
'...more stuff...
Case 2
'...more stuff...
End Select

End Sub


However the list box does not seem to update....

_________________
Sean Dotson, PE
RND Automation & Engineering
Free 30 day trial of iPropWiz v5
Follow @seandotson & @mcadforums & @rndautomationon Twitter


Share on FacebookShare on TwitterShare on DiggShare on DeliciousShare on TumblrShare on Google+
Top
 Profile  
 
 Post subject: Re: Refreshing ListBox
PostPosted: Wed Aug 08, 2012 5:09 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
Use the "MouseUp" event of the ListBox1 Object. The Click event can fire when making changes from within the event itself, putting you into recursive hell that can bypass what you are trying to do.
Code:
Private Sub ListBox1_MouseUp(ByVal Button As Integer, _
        ByVal Shift As Integer, _
        ByVal X As Single, _
        ByVal Y As Single)
       
With ListBox1
    'Button will = 1 for left-click
    If Button = 1 Then
        Select Case .ListIndex
        Case 0
            .ListIndex = -1
            .RowSource = ""
            .RowSource = Range("Frames").Address

        Case 1
       
        Case 2
       
        Case Else
        End Select
    End If
End With
End Sub

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
 Post subject: Re: Refreshing ListBox
PostPosted: Thu Aug 09, 2012 11:43 am 
Offline
Forum Admin
User avatar

Joined: 29 Jan 2004
Posts: 13448
Country: United States
State: Florida
CAD System: Inventor
Works great. Thanks Robert. I suspected it was getting confused with the click event but could not think of another way to do it.

_________________
Sean Dotson, PE
RND Automation & Engineering
Free 30 day trial of iPropWiz v5
Follow @seandotson & @mcadforums & @rndautomationon Twitter


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Exabot [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
POWERED_BY