ListBox select all items c#

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 [416] 849-8900

For everyone who is interested:

I opened a support ticket and learned, that the development team is aware of this performance issue with large multi-select ListBox.

Numeric values in ItemsData [instead of Items], should be slightly faster [~20% faster] than using Items if this is a high frequency workflow.

app = struct;

app.ListBox = uilistbox['Items', "Items" + [1:1000]];

app.ListBox.Multiselect = 'on';

app.ListBox.ItemsData = 1:1000;

tic

ItemsData = app.ListBox.ItemsData;

ReadItemsTime = toc;

tic

app.ListBox.Value = ItemsData;

WriteValueTime = toc;

disp[['Read items from the list box: ' num2str[ReadItemsTime] ' s']]

disp[['Write items to the Value variable: ' num2str[WriteValueTime] 's']]

  1. #1

    hi everybody.... i want to know how to select all the items in the listbox through code... similar to select all. i have it's equallent code in visual basic 6.0. --------------------------------- dim i as integer For i = 0 To List1.ListCount - 1 List1.Selected[i] = True Next ---------------------------------

    can any one do..

  2. #2

  3. #3

    Originally Posted by jmcilhinney

    You use the SetSelected method of the ListBox for each item.

    Thaks for your reply jmcilhinney.. i have another doubt.

    how to make invert selection in a listbox through code?

  4. #4

    VB Code:

    1. Me.ListBox1.BeginUpdate[]

    2. For index As Integer = 0 To Me.ListBox1.Items.Count - 1 Step 1

    3.     Me.ListBox1.SetSelected[index, Not Me.ListBox1.GetSelected[index]]

    The BeginUpdate and EndUpdate calls should be used if you're using VB 2005 but they are not available in previous versions. Please specify your version whenever you start a thread in future.

  5. #5

    Originally Posted by jmcilhinney

    VB Code:

    1. Me.ListBox1.BeginUpdate[]

    2. For index As Integer = 0 To Me.ListBox1.Items.Count - 1 Step 1

    3.     Me.ListBox1.SetSelected[index, Not Me.ListBox1.GetSelected[index]]

    The BeginUpdate and EndUpdate calls should be used if you're using VB 2005 but they are not available in previous versions. Please specify your version whenever you start a thread in future.

    I use Dotnet 2003. There is no begin update and endupdate in 2003. But the for loop works. It's nice.

    Thanks for ur reply.

    Last edited by softkans; Jun 7th, 2006 at 05:23 AM.

Jonesgj

Chaps, How would I select all items in a listbox using code? I'm sure its an easy one but .... Thanks

3 40499

Armin Zingler

"Jonesgj" schrieb

How would I select all items in a listbox using code?

I'm sure its an easy one but ....

For i As Integer = 0 To Me.ListBox1.Items.Count - 1 Me.ListBox1.SetSelected[i, True] Next -- Armin

Herfried K. Wagner [MVP]

Hello,

"Jonesgj" schrieb:

How would I select all items in a listbox using code?
Set the ListBox's 'SelectionMode' to 'MultiSimple' or 'MultiExtended', then you can use this code: \\\ Dim i As Integer For i = 0 To Me.ListBox1.Items.Count - 1 Me.ListBox1.SetSelected[i, True] Next i /// -- Herfried K. Wagner MVP · VB Classic, VB.NET

//www.mvps.org/dotnet


Jonesgj

Thanks Armin. "Armin Zingler" wrote in message

news:%2****************@TK2MSFTNGP12.phx.gbl...

"Jonesgj" schrieb
How would I select all items in a listbox using code?

I'm sure its an easy one but ....

For i As Integer = 0 To Me.ListBox1.Items.Count - 1 Me.ListBox1.SetSelected[i, True] Next --

Armin


Replies have been disabled for this discussion.

Video liên quan

Chủ Đề