Solved

Updating a listbox

Posted on 2006-11-08
1
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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…
Starting up a Project

632 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