Solved

Updating a listbox

Posted on 2006-11-08
1
252 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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
squareUp  challenge 22 104
nestparen challenge 4 55
topping1 challenge 7 48
C Programming - If Statement 8 47
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
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.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now