I have Form1 that has a listbox, i need to go to Form2 from Form1 and then return to Form 1, how can I keep track of the currently selected list row?
Printable View
I have Form1 that has a listbox, i need to go to Form2 from Form1 and then return to Form 1, how can I keep track of the currently selected list row?
Unless you are doing something that affects the listbox the selection won't change when you come back to the form.
Yes i am refreshing the listbox when i return to Form1.
Well then the simplest thing to do is to create a global variable and just before you go to Form2 set the value of the global variable to the Litsbox's ListIndex.
CORRECTION: I'm using a listview.
Trying to stay away from globals.
That's always a good idea.Quote:
Originally posted by mmr93
Trying to stay away from globals.
Add the following to Form1.
VB Code:
Option Explicit Private mintIndex As Integer Public Property Get ItemSelected() As Integer ItemSelected = mintIndex End Property Public Property Let ItemSelected(ByVal intNdx As Integer) mintIndex = intNdx End Property
Usage:
' To save the value
ItemSelected = MyListView.SelectedItem.Index
' To reset it
Dim itmX As ListItem
Set itmX = MyListView.ListItems(ItemSelected)
itmX.Selected = True