Auto Scroll ListView to Selected Item?

This is a discussion on Auto Scroll ListView to Selected Item? within the C# Programming forums, part of the General Programming Boards category; One of the things I liked about plain old ListBoxes is that if I changed the selectedindex in code the ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    49

    Auto Scroll ListView to Selected Item?

    One of the things I liked about plain old ListBoxes is that if I changed the selectedindex in code the list would automatically scroll so the selected item was viewable.

    I have an application that requires a ListView with a search textbox. I am able to get the matching result selected by adding it to the selectedindices collection of the ListView, but how could I (either property wise or in code) have the ListView auto-scroll so the selected item is viewable? This ListView only allows for selection of one item at a time, so its selectedindices collection never exceeds 1 item.

  2. #2
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Code:
    yourListView.EnsureVisible(index);

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    49
    Works like a charm, I was having nightmares of having to figure out the code to do it manually, now I don't need to

    Thanks for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 (C/C++) Getting selected ListView item...
    By yaya in forum Windows Programming
    Replies: 3
    Last Post: 11-23-2009, 04:41 PM
  2. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  3. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 10:44 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM
  5. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 12:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21