473,569 Members | 2,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Poor performace when selecting all items in a listbox?

So far, the quikest way I have found to select all items in a list box
is to turn off updates, set a wait cusror and then call SetSelected on
each item (see below), but it's too slow when the control is populated
with tens of thousands of items.

Ideally the wait-cursor shouldn't be needed as I hadn't anticipated a
select-all operation taking a noticeable amount of time. Has anyone
found a way to make this appear instantaneous as it would be in MFC?

Many thanks,

Duncan.

private void selectAllToolSt ripMenuItem_Cli ck(object sender, EventArgs
e)
{
if( Messages.Items. Count 0 )
{
Messages.BeginU pdate();

Cursor prevCursor = Cursor;
Cursor = Cursors.WaitCur sor;

for( int ii = 0; ii < Messages.Items. Count; ++ii )
{
Messages.SetSel ected(ii, true);
}

Messages.EndUpd ate();

Cursor = prevCursor;
}
}

Jun 7 '07 #1
4 2076
On Jun 7, 1:18 pm, Duncan Smith <DSmith1...@goo glemail.comwrot e:
Has anyone found a way to make this appear instantaneous as it would be in MFC?
<snip>
for( int ii = 0; ii < Messages.Items. Count; ++ii )
{
Messages.SetSel ected(ii, true);
}

VERY new to C# and don't know Framework library (and therefore
implications) but following code worked much better for 5000 list
items/rows compared to "SetSelecte d"-

for( int ii = 0; ii < Messages.Items. Count; ++ii )
{
Messages.Select edIndex = ii;
}

Thanks,
Neel.

Jun 7 '07 #2
You could try using a ListView instead of a ListBox.
Then replace
Messages.SetSel ected(ii, true);
with
Messages.Items[ii].Selected = true;
There are a few other properties you have to set on a ListView to make
it look like a ListBox. And the Items array is a different type of
object which is a bit of a pain.
for( int ii = 0; ii < Messages.Items. Count; ++ii )
{
Messages.Select edIndex = ii;
}
Um, I don't think that code snippet is quite the same as the original.
He wanted to select all, not select all one at a time.

Jun 7 '07 #3
On Jun 7, 12:59 pm, not_a_commie <notacom...@gma il.comwrote:
You could try using a ListView instead of a ListBox.
Then replace
Messages.SetSel ected(ii, true);
with
Messages.Items[ii].Selected = true;
There are a few other properties you have to set on a ListView to make
it look like a ListBox. And the Items array is a different type of
object which is a bit of a pain.
for( int ii = 0; ii < Messages.Items. Count; ++ii )
{
Messages.Select edIndex = ii;
}

Um, I don't think that code snippet is quite the same as the original.
He wanted to select all, not select all one at a time.
Thanks, I had to go with a ListView in the end anyway for the
EnsureVisible() method, so the most recently added item could be made
to be scrolled into view.

I found the quickest way to select all items was to use SendKeys(), I
hope it's not considered bad practice, certainly seems the most
responsive course given a densely populated control (see snippet
below):

Regards,

Duncan.

/// <summary>
/// Selects all items from the messages listview
/// </summary>
/// <param name="sender">C alling object</param>
/// <param name="e">args</param>
private void selectAllToolSt ripMenuItem_Cli ck(object sender,
EventArgs e)
{
if (Messages2.Item s.Count 0)
{
Messages2.Focus ();
SendKeys.SendWa it("{HOME}");
SendKeys.SendWa it("+{END}");
}
}

Jun 7 '07 #4
On Jun 7, 6:43 pm, Duncan Smith <DSmith1...@goo glemail.comwrot e:
I found the quickest way to select all items was to use SendKeys()
Yes, I had thought of that but I didn't know how to do that in new
framework (used of doing it in MFC), but, thanks to you, I know now.
In addition to that, the time that it takes to select _all_ items, no
matter how many, with HOME + END characters when done manually through
keyboard, didn't feel right. So, when with your example I tried it
with 10,000 items. With "Messages.Selec tedIndex = ii;", if you had a
event handler defined for "SelectedIndexC hanged" it will be called for
every item. But, with "SendKeys" it will be called _only_ for two
items (first and last). For some of the applications it would be okay,
for some of them its not I guess.

Thanks,
Neel.

Jun 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2321
by: Mark | last post by:
Hi - is it possible to pass a comma delimeted list to a javascript function, which will then loop through the list, and check against a listboxs items, and if the value in the list, corresponds to an item in the listbox, the listbox item should be 'selected' - I'd like this to happen for a multiple select list box. Something along the lines...
5
1527
by: Lada 'Ray' Lostak | last post by:
Dear list, First of all I want to say sory, if my question was answered somewhere. Or if it is my fault. If so, please, give me link/hint. My own search fails :( I have experimence with MySql, MsSql and Oracle (and MS Access huch :) I am new to PgSql. We are running server - OpenBSD 2.9, latest apache, latest PHP, latest PgSql, latest...
3
3529
by: Alpha | last post by:
I have 3 radio buttons for include, exclued or 'select all' from the listbox items. If a user selects the 'Select All' button' then all items in listbox is hi-lited as selected. Now, when user selects one item out of the 'all selected' listing then there is now only one item selected. How and where can I put in some code to change the...
4
11483
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you select, the first one in the listbox is always removed.(The listitem with an index of 0. Box is set to single selection mode) I've looked at...
3
41913
by: Jonesgj | last post by:
Chaps, How would I select all items in a listbox using code? I'm sure its an easy one but .... Thanks
4
17407
by: John | last post by:
Hi there, I'm just starting at VB.NET (all VB come to that), and have what's probably a very basic question: I have a form in Visual Studio 2003 that has a listbox that is meant to be populated with file names from the OpenFileDialog method (see below). The problem is that if you select, say three files in the Open File dialogue box,...
14
18673
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe is that as more and more are added, population of the list box takes longer and longer. ie the first 10th of the item set are added much much...
2
4016
Airslash
by: Airslash | last post by:
Hello, currently I'm working on a company project where they have created a custom FileOpenDialog component. In this component they have a function to get all the Physical drives on a system and return the free space. At the moment this function is extremely slow. The original code use to take about 28 seconds to fetch all the information...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.