How to persist listbox current item
-
I use single-select WinForms ListBox control in C# .NET 2 application. Every time when I run my appl, listbox shows first item as current item. How to persist listbox current item in user isolated storage ? I need that when my application rans next time, listbox dispays item which was selected in previous ran.
Andrus
-
I use single-select WinForms ListBox control in C# .NET 2 application. Every time when I run my appl, listbox shows first item as current item. How to persist listbox current item in user isolated storage ? I need that when my application rans next time, listbox dispays item which was selected in previous ran.
Andrus
I assume the list box contains a static list of items that never changes? If so, this would be (one) way to do it: 1. Create a new user setting 'MyListBoxIndex' of type Int. 2. Create a SelectedIndexChanged event handler for the listbox. 3. In the handler, store the current index using: Properties.Settings.Default.MyListBoxIndex = myListBox.SelectedIndex; 4. After the Application.Run() exits, call Properties.Settings.Default.Save() Whenever the form / control loads that has your listbox on it, retrieve the index from the user setting and select the corresponding index using myListBox.SelectedIndex = Properties.Settings.Default.MyListBoxIndex; Hope this helps, Roel