Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How to persist listbox current item

How to persist listbox current item

Scheduled Pinned Locked Moved Windows Forms
csharpwinformstutorialquestion
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrusM
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • A AndrusM

      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

      R Offline
      R Offline
      roel_v
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups