Solved

Updating a listbox

Posted on 2006-11-08
1
280 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 85

Accepted Solution

by:
Mike Tomlinson earned 250 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

839 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