473,503 Members | 2,152 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 selectAllToolStripMenuItem_Click(object sender, EventArgs
e)
{
if( Messages.Items.Count 0 )
{
Messages.BeginUpdate();

Cursor prevCursor = Cursor;
Cursor = Cursors.WaitCursor;

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

Messages.EndUpdate();

Cursor = prevCursor;
}
}

Jun 7 '07 #1
4 2074
On Jun 7, 1:18 pm, Duncan Smith <DSmith1...@googlemail.comwrote:
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.SetSelected(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 "SetSelected"-

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

Thanks,
Neel.

Jun 7 '07 #2
You could try using a ListView instead of a ListBox.
Then replace
Messages.SetSelected(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.SelectedIndex = 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...@gmail.comwrote:
You could try using a ListView instead of a ListBox.
Then replace
Messages.SetSelected(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.SelectedIndex = 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">Calling object</param>
/// <param name="e">args</param>
private void selectAllToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (Messages2.Items.Count 0)
{
Messages2.Focus();
SendKeys.SendWait("{HOME}");
SendKeys.SendWait("+{END}");
}
}

Jun 7 '07 #4
On Jun 7, 6:43 pm, Duncan Smith <DSmith1...@googlemail.comwrote:
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.SelectedIndex = ii;", if you had a
event handler defined for "SelectedIndexChanged" 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
2317
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...
5
1523
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,...
3
3525
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...
4
11475
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...
3
41893
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
17378
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...
14
18633
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...
2
4004
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...
0
7205
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,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7008
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...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5022
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...
0
3177
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...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.