Click here to Skip to main content
13,140,231 members (50,183 online)
Rate this:
Please Sign up or sign in to vote.
Im trying to select all items in a listbox by clicking a "Select all" button,
and i got some info from MSDN website,[^]
However when i try to use "Select All" method,it shows that such method could not be found.

I had already import the reference PresentationFramework.dll to my solution.
Posted 14-Aug-12 19:36pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Wait! You have confused everything! This has nothing to do with VisualStudio. And either you use WPF or WindowsForms control. PresentationFramework.dll is WPF, the link is for the WindowsForms control.
To allow user to select all elements in wpf listbox look here:[^]
If you want to select programatically all elements, you can use the SelectedItems[^] property, and add all elements from the bound source (don't forget to set multiple selection mode[^])
asdf9009 15-Aug-12 2:02am
thanks for telling me,
i was doing a project in Windows Forms!
So, can i get"SelectAll" method in Windows Forms environment?
Zoltán Zörgő 15-Aug-12 2:17am
The standard control does not have such method, only the wpf control. Use this code line:
for(int i=0; i<listBox1.Items.Count; i++) listBox1.SetSelected(i,true);
And don't forget to set SelectionMode.

You can also make an extension method, if you want to use it many times:

using System;
using System.Windows.Forms;

namespace my
public static class ListBoxExtensionMethods
public static void SelectAll(this ListBox listbox, bool selected = true)
for(int i=0; i<listbox.Items.Count; i++) listbox.SetSelected(i,selected);

public static void DeselectAll(this ListBox listbox)
SelectAll(listbox, false);

asdf9009 15-Aug-12 17:23pm works now...more to learn...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 15 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100