J
J Streger
I have two listboxes in a form. I have set them up to move data from one form
to the other via buttons (the list items are removed from box one and added
to box two and vice versa). This all worked beautifully. Then I set up
dbl-clck events for each listbox, so the user can double click on an entry to
move it to the other listbox.
this works fine, except after the code is done running, the top value in the
listbox they selected and the value directly under the value they selected
are now selected.
If I run the code stepping through the lines, this doesn't happen at all. I
am using the exact same code for the button to move a value as I am for the
double-click. I even added a method to forcibly deselect all values in the
listbox, yet they are still selected.
Is this a bug in the listbox code itself? Anyone else have this issue? Below
is some of the code I use. These are the only methods that affect the
listboxes, as the others may read from them but do not touch the values.
Thanks.
'***********************************************************
'*Name: lboAvailable_DblClick
'*Description: This event will add the selected value the user double
'* clicked on to the lboSelected Listbox
'*Input Params: Cancel - MSForms.ReturnBoolean - System Generated
'*Returns: None
'*Written by Jared Streger, 3/18/08
'***********************************************************
Private Sub lboAvailable_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'Move value
AddSelected
'Enforce a Deselect of all values in lboAvailable
DeSelectAllValues lboAvailable
End Sub 'lboAvailable_DblClick
'***********************************************************
'*Name: AddSelected
'*Description: This method will transfer all the selected items
'* in the lboAvailable Listbox to the lboSelected
'* listbox. It should deselect all values as well.
'*Input Params: bAll - optional Boolean - True if all values should
'* be transferred, false if just the selected values
'8 should be transferred
'*Returns: None
'*Written by Jared Streger, 3/18/08
'***********************************************************
Private Sub AddSelected(Optional bAll As Boolean = False)
Dim colSel As Collection
Dim colAvl As Collection
'Get Collection of selected values
Set colAvl = GetBoxValues(lboAvailable, Not bAll)
'Get Data in Selected
Set colSel = GetBoxValues(lboSelected)
'Add Box values to selected values
Set colSel = JoinCollections(colSel, colAvl, False)
'get all Available Columns
Set colAvl = GetBoxValues(lboAvailable)
'Remove selected values from available
RemoveSelectedFromAvailable colSel, colAvl
'Add values to listboxes
AddCollectionsToListBoxes colSel, colAvl
End Sub 'AddSelected
'***********************************************************
'*Name: AddCollectionsToListBoxes
'*Description: This method will add the passed in collections to
'* to lboAvailable and lboSelected Listboxes.
'*Input Params: colSel - Collection - Collection to be added to lboSelected
'* colAvl - Collection - Collection to be added to lboAvailable
'*Returns: None
'*Written by Jared Streger, 3/18/08
'***********************************************************
Private Sub AddCollectionsToListBoxes(colSel As Collection, colAvl As
Collection)
Dim columns() As Variant
Dim columnsSel() As Variant
'Clear both listboxes
lboAvailable.Clear
lboSelected.Clear
'Convert collection to array
columns = fCollectionToArray(colAvl)
columnsSel = fCollectionToArray(colSel)
'Add arrays to listboxes
If colAvl.Count > 0 Then lboAvailable.List = columns
If colSel.Count > 0 Then lboSelected.List = columnsSel
End Sub 'AddCollectionsToListBoxes
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003
User of MS Office 2003
to the other via buttons (the list items are removed from box one and added
to box two and vice versa). This all worked beautifully. Then I set up
dbl-clck events for each listbox, so the user can double click on an entry to
move it to the other listbox.
this works fine, except after the code is done running, the top value in the
listbox they selected and the value directly under the value they selected
are now selected.
If I run the code stepping through the lines, this doesn't happen at all. I
am using the exact same code for the button to move a value as I am for the
double-click. I even added a method to forcibly deselect all values in the
listbox, yet they are still selected.
Is this a bug in the listbox code itself? Anyone else have this issue? Below
is some of the code I use. These are the only methods that affect the
listboxes, as the others may read from them but do not touch the values.
Thanks.
'***********************************************************
'*Name: lboAvailable_DblClick
'*Description: This event will add the selected value the user double
'* clicked on to the lboSelected Listbox
'*Input Params: Cancel - MSForms.ReturnBoolean - System Generated
'*Returns: None
'*Written by Jared Streger, 3/18/08
'***********************************************************
Private Sub lboAvailable_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'Move value
AddSelected
'Enforce a Deselect of all values in lboAvailable
DeSelectAllValues lboAvailable
End Sub 'lboAvailable_DblClick
'***********************************************************
'*Name: AddSelected
'*Description: This method will transfer all the selected items
'* in the lboAvailable Listbox to the lboSelected
'* listbox. It should deselect all values as well.
'*Input Params: bAll - optional Boolean - True if all values should
'* be transferred, false if just the selected values
'8 should be transferred
'*Returns: None
'*Written by Jared Streger, 3/18/08
'***********************************************************
Private Sub AddSelected(Optional bAll As Boolean = False)
Dim colSel As Collection
Dim colAvl As Collection
'Get Collection of selected values
Set colAvl = GetBoxValues(lboAvailable, Not bAll)
'Get Data in Selected
Set colSel = GetBoxValues(lboSelected)
'Add Box values to selected values
Set colSel = JoinCollections(colSel, colAvl, False)
'get all Available Columns
Set colAvl = GetBoxValues(lboAvailable)
'Remove selected values from available
RemoveSelectedFromAvailable colSel, colAvl
'Add values to listboxes
AddCollectionsToListBoxes colSel, colAvl
End Sub 'AddSelected
'***********************************************************
'*Name: AddCollectionsToListBoxes
'*Description: This method will add the passed in collections to
'* to lboAvailable and lboSelected Listboxes.
'*Input Params: colSel - Collection - Collection to be added to lboSelected
'* colAvl - Collection - Collection to be added to lboAvailable
'*Returns: None
'*Written by Jared Streger, 3/18/08
'***********************************************************
Private Sub AddCollectionsToListBoxes(colSel As Collection, colAvl As
Collection)
Dim columns() As Variant
Dim columnsSel() As Variant
'Clear both listboxes
lboAvailable.Clear
lboSelected.Clear
'Convert collection to array
columns = fCollectionToArray(colAvl)
columnsSel = fCollectionToArray(colSel)
'Add arrays to listboxes
If colAvl.Count > 0 Then lboAvailable.List = columns
If colSel.Count > 0 Then lboSelected.List = columnsSel
End Sub 'AddCollectionsToListBoxes
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003
User of MS Office 2003