I have a class (which I didn't write but found online) that allows me to select a listbox row and all the items in the same row move up or down via 2 up/down command buttons.
I also have a further 2 listboxes and a further 2 pairs of addition command buttons. Admittedly, I don't fully understand classes yet however I was able to tweak the existing code so that each pair of command buttons moves the selected item up or down in the adjacent listbox by creating 2 further instances of the class. I would however prefer to have a single pair of up/down buttons which would operate on the selected item in any of the listboxes. I have also set the click event in each of the listboxes to deselect any selected items in the other 2 listboxes.
Some code:
Form declarations(3 instances for each pair of up/down buttons):
Private m_clsListMoveUpDown1 As CListbox_UpDown Private m_clsListMoveUpDown2 As CListbox_UpDown Private m_clsListMoveUpDown3 As CListbox_UpDown
and then instantiating the 3 instances of the class (within the form) via:
Set m_clsListMoveUpDown1 = New CListbox_UpDown With m_clsListMoveUpDown1 Set .MoveDownButton = Me.Btn_MoveDown1 Set .MoveUpButton = Me.Btn_MoveUp1 Set .UpDownList = Me.LB_Sheet1 End With Set m_clsListMoveUpDown2 = New CListbox_UpDown With m_clsListMoveUpDown2 Set .MoveDownButton = Me.Btn_MoveDown2 Set .MoveUpButton = Me.Btn_MoveUp2 Set .UpDownList = Me.LB_Sheet2 End With Set m_clsListMoveUpDown3 = New CListbox_UpDown With m_clsListMoveUpDown3 Set .MoveDownButton = Me.Btn_MoveDown3 Set .MoveUpButton = Me.Btn_MoveUp3 Set .UpDownList = Me.LB_Sheet3 End With
Finally, some class declarations:
Public WithEvents MoveUpButton As MSForms.CommandButton Public WithEvents MoveDownButton As MSForms.CommandButton Public UpDownList As MSForms.ListBox
Now, this all works just fine but it seems a bit overkill have 3x the code and 2 extra pairs of buttons which doesn't look that great on my userform. I haven't included either of the 2No. subroutines within the class but can do if it helps. In a nutshell they contain:
With Me.UpDownList 'lines of code using arrays to move items up or down End With
I completely understand the reason why a single pair of up/down buttons currently only operates on the listbox specified by e.g. Set .UpDownList = Me.LB_Sheet1 however am I wondering if its possible to create only 1 instance of the class and have it operate on the listbox with the currently selected item?