Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Updating a listbox

Posted on 2006-11-08
1
Medium Priority
?
301 Views
Last Modified: 2010-04-16

Hey, I am adding buttons to select all or clear all in a listbox.  So far I have:

    Private Sub ButtonSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSelectAll.Click

        For n As Integer = 0 To Me.ListBoxMonitors.Items.Count - 1
            Me.ListBoxMonitors.SetSelected(n, True)
        Next

    End Sub

This is fine except (a) there are many items, so it looks slow/ugly, and (b) it changes the scroll position.  Anybody have code that doesn't screw up the scroll position, and is there a function that allows me to suspsnd redrawing of the listbox until I've done everything I need to do?

Thanks in advance.
0
Comment
Question by:riceman0
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 17902602
Something like...

    Private Sub ButtonSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSelectAll.Click
        ListBoxMonitors.BeginUpdate()
        Dim prevTopIndex As Integer = ListBoxMonitors.TopIndex
        For n As Integer = 0 To Me.ListBoxMonitors.Items.Count - 1
            Me.ListBoxMonitors.SetSelected(n, True)
        Next
        ListBoxMonitors.TopIndex = prevTopIndex
        ListBoxMonitors.EndUpdate()
    End Sub
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Make the most of your online learning experience.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Loops Section Overview

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question