Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Problems with control events


Message #1 by "Mark Phillips" <mark@p...> on Wed, 29 Jan 2003 02:46:15
try:

Private Sub lstDocuments_Click()
    'turn off the checkbox
    chkSelectAll.Value = 0
End Sub

later,
bware

-----Original Message-----
From: Mark Phillips [mailto:mark@p...]
Sent: Wednesday, January 29, 2003 2:46 AM
To: professional vb
Subject: [pro_vb] Problems with control events


I have a listbox and a checkbox. When the user clicks on the checkbox, 
then all the items in the listbox must be selected, and when the user 
unchecks the checkbox all the items in the list box are deselected. Now, 
this works just fine.

However, if the user has selected all the items in the listbox, and then 
selects just one (i.e. a click event), I want to turn off the checkbox 
(i.e. set it to unChecked). However, I get into a infinite loop of 
events...

Private Sub chkSelectAll_Click()
    Dim i As Long, lngSaveIndex As Long, lngSaveTop As Long, intValue As 
Integer
    'Save current state
    lngSaveIndex = lstDocuments.ListIndex
    lngSaveTop = lstDocuments.TopIndex
    intValue = chkSelectAll.Value
    'Make the listbox invisible to avoid flickering
    lstDocuments.Visible = False
    'Change the selected state based on the checked value of the checkbox
    For i = 0 To lstDocuments.ListCount - 1
        lstDocuments.Selected(i) = (intValue = vbChecked)
    Next
    'Restore the original state
    lstDocuments.TopIndex = lngSaveTop
    lstDocuments.ListIndex = lngSaveIndex
    lstDocuments.Visible = True
End Sub

Private Sub lstDocuments_Click()
    'turn off the checkbox
    chkSelectAll.Value=vbUnchecked
End Sub


How do I get out of this problem?

Thanks!

Mark



  Return to Index