Click here to Skip to main content
15,890,512 members
Everything / ListBox

ListBox

ListBox

Great Reads

by Nilay M Joshi
Multiselect Combobox - Custom control for WPF
by Magnus_
public static void RemoveSelected(this ListControl source){ foreach (var item in source.Items.Cast().Where(li => li.Selected).ToList()) source.Items.Remove(item);}protected void btnRemove_Click(object sender, EventArgs e){ lstCity.RemoveSelected();}
by Evren Yortuçboylu
A checkbox list jQuery UI widget with real time filtering functionality explained
by Paul_Williams
The difference between ListBox and CheckedListBox DataBinding.

Latest Articles

by Martin Henke (1971)
Edit Metadata for folders by using desktop.ini features
by Nilay M Joshi
Multiselect Combobox - Custom control for WPF
by Michael Shpilt
A WPF tutorial on how to create FilteredListView: A ListView custom control with search filter that uses Throttling.
by davekahn
An easy way to control the lists of options in multiple related SELECT controls

All Articles

Sort by Updated

ListBox 

19 Oct 2010 by "Fish" (David B. Trout)
Simple parsing of VS_VERSIONINFO version information strings displayed in an XP-style file-properties "Version" tab
9 Jul 2010 by #realJSOP
I wrote an article that customizes the drawing in a ListBox. Anagrams - A Word Game in C#[^]The following is an excerpt of the appropriate section of the article:The Word ListI wanted a way to show the user what he'd typed, so I decided on a list box. As the program validates...
17 Oct 2010 by #realJSOP
Or something like this:foreach (object item in listbox.SelectedItems){ // do domething}In my case, I'd put a property into the "item" object that returns an XML representation of the object, and pass that to the database. That way, the loop shown above would look something like...
10 Feb 2011 by #realJSOP
Try this:ta = cbxGenre.SelectedText;Have you considered using the debugger?
21 Sep 2011 by #realJSOP
Save the frames with different names, or release the files handles you're using. Those are your only options.
4 Nov 2014 by #realJSOP
I can't for the life of me finger out why I'm not getting a selection highlight in my listboxes. There are no merged resource dictionaries, and there are no style ovverrides defined within parent's resources.Selection appears to work (it's doing what it's supposed to do when I make a...
25 Jan 2017 by #realJSOP
0) You don't have to return anything. Just have a property in your list item class called IsSelected, and set it to true when a selection is made in the bound listbox.1) The ListBox control allows you to page by clicking the scrollbar arrows. I don't understand why you feel that you need a...
5 Feb 2015 by /\jmot
why didn't you search on google???Ref.http://stackoverflow.com/questions/14826495/listbox-selected-item-in-a-textbox[^]passing textbox values to listbox[^]
1 Mar 2014 by _Asif_
Try thisListBox with Custom Scrollbar[^]
1 Jan 2017 by _PitrakSarkar_
Hi,I am able to handle the mouse move events and get the mouse coordinates on the dialog; but when the mouse moves inside a ClistBox, I am not able to get the coordinates. Could you please help?What I have tried:I am able to get the mouse coordinates when I move the mouse on the...
1 Jan 2017 by _PitrakSarkar_
I am writing this answer so that others can get help in case some one else is facing this problem. First things first; you can't directly handle mouse move messages from Clistbox. So, you create a new class based on ClistBox class and then handle OnMouseMove() in that class.Then, inside that...
16 Oct 2012 by Aarti Meswania
If you have load data in DropDownList as below,DropDownList1.DataSource = DtCategoryDropDownList1.ValueMember = "Cate_id"DropDownList1.DisplayMember = "Category"then,dropdownlist will have value as belowdropdownIndex ValueMember Displaymember0 1 Books1 ...
9 Dec 2011 by abdalkareem
How to search for a word in the listbox by textbox in C #. Net
2 Feb 2014 by Abdullaziz Said
Hello as title said how to add selected multiple items in listbox to database every selected item to new record i have listbox that bounded from database and i want to add every selected item to new record in sql server DB iam using C# more explain i want every item that i select...
4 Feb 2014 by Abdullaziz Said
helloanother thing iam trying to add more thank one filed but i get error foreach (ListItem lst in test_names.Items) { if (lst.Selected) { string selectedValue = lst.Value; string patient_id =...
3 Jun 2014 by abhicoolhot
Hi,I was trying to list all the files and folders in C drive in listbox using C#, but couldn't able to succeed.Could you please help me on this below task,A button click to list down all the files and folders present on C drive in "ListBox".
5 Jun 2014 by abhicoolhot
Hi,Am facing one problem in my listbox on using C#. Please see the details below,I have two buttons and one listbox. On clicking first button i will get files/directories present on C drive get listed on listbox when I clicked second button to list down selected directory files. When I...
17 Oct 2010 by Abhinav S
See the last post in this[^] thread.
4 Dec 2010 by Abhinav S
Put a debug point at the first if condition and then debug to check 1) the ta value2) whether your code goes into any of these if conditions.
10 Feb 2011 by Abhinav S
It is difficult to figure out what could be wrong without looking at the code / design that binds genres to the combo.At best, for a simple example see here[^].This might give you an idea as to what you might be doing wrong.
26 Oct 2011 by Abhinav S
List row Indexes = new List();This line wont even compile.So make sure you have copy pasted the right code here. This will help someone assist you better.
9 Dec 2011 by Abhinav S
Obtain the value from the textbox and then use the FindString method inside a Listbox. See here[^].
6 Jun 2011 by adam4l
I'm learning the basics of listbox recently, and til now I've learned these things:TextBox1button1 button2 ListBox1and I've written the following code:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using...
4 Aug 2013 by adi jeevan sagar
i have a list-box with data template as text-block and i am binding observable collection of some strings .on mouse enter of list-box items if the listboxitem is greater than list-box width i want to show ending of list-box item as "..." . for example : thisisastring... (normal behavior) . but...
12 Jun 2015 by Aditya_Goud
I have a string ,i will get this data from server under XElement, i have made it into a string and it looks like say 9000384454|130945522842|13098575900|917379563772|919014742532|99484575475do i need to parse to add these kind of data i need to add these each number into list box as...
25 Jul 2011 by adnama
i have a listbox, and i want to save the items into an xml file.this is the code to save: try { XmlSerializer serializer = new XmlSerializer(typeof(string)); TextWriter tw = new StreamWriter("C:\\Users\\Lifebook\\Desktop\\Usage...
30 Dec 2010 by Adriaan
Hi there, thanks for the answers. What if i use a storyboard for the border color change and play the story board onTextChanged? Is this a bad way of doing it?Hi there, i was wondering if someone can assist with tips on the following:1. I added a listbox with five listbox items (Name...
30 Dec 2010 by Adriaan
Hi there, thanks for the answers. What if i use a storyboard for the border color change and play the story board onTextChanged? Is this a bad way of doing it?
11 Dec 2018 by Afzaal Ahmad Zeeshan
Quote: I need to search one directory (c:\K_txt) of almost 3,000 .txt files Searching this on the fly is a really very bad idea, and would have to make your users wait each time they make a change in the query. A good approach would be to read your files once, and create tokens (words, in...
17 Feb 2015 by agent_kruger
I want to create a list that searches and retrieves all the data in list which is matching the searching criteria (the text to search can appears anywhere in the list's string start,middle,end)Sample Image Of What I Want To AchieveNow, the situation is i can handle the searching part...
5 Jul 2019 by Ahmad_kelany
hi everyone,i searched for changing ListBoxItem back color and persisting this selection color even if the control lost focusi found the solution like this :
16 Sep 2016 by Ahmad_kelany
Hi everyoneI have a DataTemplate : ...
23 Apr 2013 by ahmetkocadogan
i have a listbox contains some brand names of products. i make them a string with a for loop like :string kod;string grupkodu;for (int i = 0; i
15 Oct 2013 by Ajay J Singh
ListBox.Items.Remove(index);...
18 Jun 2013 by akosisugar
Hello experts! im creating an advanced media player in vb.net. After exectuing the code from the AxWindowsMediaPlayer1_PlayStateChange event I want to autoplay the new selected item inside the listbox. Just like windows media player.Can you help me with my code please!Private Sub...
17 Mar 2011 by Ali Al Omairi(Abu AlHassan)
Please, See this i think it will help.100 :rose:Tommorow we will build our glory !!
12 Apr 2012 by Alimjan Yasin
I am having problem triggering button which place inside a Datatemplate which is designed for render listboxitems.listboxitem has a data source as shownpublic class WordListItem : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; ...
12 Apr 2012 by Alimjan Yasin
I solved the problem myself, I put name to UserControl and in bining of button specified it by setting ElementName , and it worked. by yesturday when I did something similar like it, it throw error, but today it worked
19 Jun 2014 by Alugoju Siva Krishna
I have a ListBox in my WPF application where i am generating my ListBox items using a Datatemplate so in my Datatemplate i have some textboxes where i want taborder for Textboxes, How to achieve this i tried many ways but of no use.Below is my XAML code :-
19 Dec 2011 by Amir Mahfoozi
It seems that you need virtualization in wpf , so have look at these pages :WPF: Data...
7 Jul 2022 by AmirSina Mashayekh
Hello. I'm creating a windows program (Visual Studio - C#) to communicate with AVR MCU using serial port. I want to show available serial ports in a ListBox (or combobox) and update the list immediately when a new device is available or a device is disconnected. Currently I use a "Refresh"...
27 Nov 2011 by amit_upadhyay
my app uses a list to store some urls and multi threading to download each url. The problem is that in current method all threads are created at once. I want to be able to use 25 threads, then wait for them to finish and then use another 25 threads. Now the question is how do i check whether the...
14 Dec 2011 by AmitGajjar
Hi,what you need to do is , you need to update every item of the list. so on click event of your up/down arrow key execute Update method. Update method will update list item order for every item.hope this will help you,thanks-amit.
11 Mar 2012 by amrutd
I have problem while grouping in listbox. Actually my table structure is as follows.Emp_ID EmpName EmpParent_ID1000002 Vivek 10000051000003 Rohit 10000051000005 Ajay 10000311000006 Sanjay 10000051000011 Hemant -11000022 Amit 10000051000024 Aakash ...
17 Jun 2011 by anandbprem
A dropdown with multiple checkbox list.After, I select some options and click on apply.then the selected list from the dropdown must list out in a listbox.Any suggestions, how to procede with this requirement.
10 Sep 2015 by Andy Lanng
ListBox1.Items contains a collection of ListItem objects. I think ToString() should work, but it's safer to use the object type and get the text or value depending on what you need://you don't have to keep creating new commands. just use a parameter. It's safer...
7 Apr 2012 by anilkumar_pandya
hi,friends; I am new in mvc3. and i want to get data of listbox to controller when form is post. i have get form data with team.cs file and create property public List availableteam { get; set; } for geting listbox data but it is display null value. and i have been used
15 Sep 2011 by Anup Das Gupta (asteranup)
Hi,Try this-HTML- a b
1 Jul 2014 by anup.bhunia
Its not very easy if not impossible with before HTML5, but with HTML5 it is pretty straigth forward. You can do that in client side itself using file read API in HTML 5;var reader = new FileReader();FileReader.readAsText(f); //f is a file selected by the user in the file input...
24 Oct 2011 by ariez88
Hi ,I m using VS2008 with SQL server 2008 at the backend. I m creating a windows application in which I have 2 listboxes.the data is being retrieved from SQL server database in listbox1.i want to select few itms from this listbox and add them to second one through add button. PROBLEM: the...
27 Oct 2011 by ariez88
I m selecting items from one listbox and adding them to second listbox on button click.the problem is tht when i want to deselect the selected items from listbox2, it gives "Object reference not set to an instance of an object" error.Below is the code I added behind SELECT button.I have used the...
22 Dec 2021 by asaad kittaneh
0 I'm building my first Tkinter GUI, and I need to create a multi-column Listbox using TKtreectrl, but when importing the module I get this error, import error: No module named "TkTreectrl". How to solve this problem, thanks in advance. What I...
14 Aug 2012 by asdf9009
Im trying to select all items in a listbox by clicking a "Select all" button,and i got some info from MSDN website,http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.selectall.aspx[^]However when i try to use "Select All" method,it shows that such method could not be...
19 Mar 2014 by Asgard25
Try this, I use it all the timesmodule is your sql connection stringUsing sqlCon = New SqlConnection(sModule) sqlCon.Open() Dim cmd As New SqlCommand("your sql query which returns two values ", sqlCon) cmd.ExecuteNonQuery() Dim adp As...
23 May 2012 by Ashish Sehajpal
You mean to say you want some sort of cascade List boxfunctionality?i.e. you have shown some DEPARTMENTs from your SQL server into a List Boxand now you want that based on what selection has been made in List Box i.e. let's say "Accounts" department has been selected rom list box and...
5 Oct 2013 by Ashish159
I am new to C# programming and currently working on Windows Forms. Just want to gain some knowledge on 'DataBinding' but unsuccessful till now. I did an extensive research on Internet but couldn't understand what DataBinding is meant for and how does it work. What I have come to know is that we...
16 Oct 2012 by AshishChaudha
For getting the CategoryID you have to specify the name of your Category Dropdownlist, like as followsddlCategory.SelectedValueYou will get the value of your category and save it in database.Thanks
3 Apr 2022 by Ashkan X
Does anyone know how to split items in listbox / 5? Automatically, this items / 5 and split to 5 other listboxes. For example, we have 1000 items in Listbox 1. I want to split these 1000 items to the 5 different listboxes. What code should I...
1 May 2012 by asinefa
I have MVVM application, my first MVVM app. So, I need to make a contextMenu in ListBox. I tried this:In xaml code
1 May 2012 by asinefa
Thx.But, as for Solution 1, with my sc it doesn't work.As for Solution 2, I didn't undestand about object listParameter and what to do with it.
1 May 2012 by asinefa
Thank you, but I set breakpoint and it doesn't go to RemoveUserCommand. maybe something wrong with xaml. I used Solution 1 too.
11 Oct 2013 by ASP.NET Community
Concept A very common question asked on the ASP.NET Forums is how to bind a ListControl's DataTextField or DataValueField to multiple Columns. The
11 Oct 2013 by ASP.NET Community
The ListBox control is used to create a list control that allows single or multiple item selection. Use the Rows property to specify the height of
10 May 2013 by Aydin Homay
Hi NirmalPlease change your binding solution, your solution is not good solution so please review follow of links and use list box DataSource property for this purpose, if you have a any question after review these links please take a comment for me ;)...
13 May 2013 by Aydin Homay
Hi againIt is really easy just you should register SelectedIndexChanged event for listbox2 and make your query follow of :void listBox1_SelectedIndexChanged(object sender, EventArgs e) { string bindingQuerylistBox2 = string.Empty; bindingQuerylistBox2 = "select *...
13 May 2013 by Aydin Homay
private void Form2_Load(object sender, EventArgs e) { SqlConnection cs = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=details;User ID=sa;Password=P@ssw0rd"); SqlCommand cmd = new SqlCommand(); cmd.Connection = cs; ...
23 Jan 2011 by bachasafyan
i want to delete from database(access) multiple records which are matching to a listbox(in c#)so how can i do that?
24 Oct 2011 by Bala Selvanayagam
I belive you wanted to add the selected item to the listbox2 and remove it from listbox1 and the following should help..try { listBox2.Items.Add(listBox1.SelectedItem); listBox1.Items.Remove(listBox1.SelectedItem); } catch...
7 Aug 2016 by Beginner Luck
duplicates.Select(c => { c.value = txtbox.Text; return c; }).ToList()
29 May 2015 by Bernhard Hiller
There is some strange behavior of a binding getting lost. I experienced something similar with a combination of a combobox and a textbox, with Textbox.Text bound to the ID property of a DependencyProperty which is in turn bound to the SelectedItem of the combobox; the user could type the id...
11 May 2016 by Bernhard Hiller
Also look at the Proxy Pattern described by Gamma et al (the "Gang of Four"). Such slow loading of images was taken as an example for the motivation behind that pattern.
27 Dec 2011 by bessy christina
how to add items to a listbox dynamically by getting values in a textbox..
12 Sep 2013 by Bilaal John S
Please use a Data-template for the list box Thanks,Bilaal
25 Aug 2013 by BillWoodruff
First, to the issue of other Controls "showing through:" unless you are using a UserControl that implements transparency (and getting a Windows Form UserControl to have any useful transparency is a dubious proposition), the only way any other control can "show through," is if it is placed on top...
23 Mar 2014 by BillWoodruff
After playing with the CheckedListBox a while, I am convinced you will find it much easier to implement this using two ListBoxes. The ListBox offers you built-in sorting by setting its 'Sorted Property to 'true.If you still really wish to use a CheckedListBox, hopefully this code will give...
11 Oct 2014 by BillWoodruff
'Utils is a Class, but in your code you never create an instance of that class.Like this: Utils currentUtils = new Utils();Once you have an instance of the Class, you can access the Public ListstringListLike this (in your Main Form):foreach(string receivableItem in...
11 Nov 2014 by BillWoodruff
For the lboxCity.Items.Clear(); method to fail with a null reference error means lboxCity was not created, or you have done something to delete the Control, or you have assigned something else, like 'null, to the name 'lboxCity.Put a break-point in your code on the line where you execute...
12 Nov 2014 by BillWoodruff
If you are speaking of the standard Microsoft ListBox Control for WinForms available since .NET 1.1, then you are mistaken: that Control does expose a 'MultiExtended option for the 'SelectionMode property.Edit: OP has revealed this is a question about the WPF ListBox.The WPF ListBox...
11 Oct 2021 by BillWoodruff
You just discovered the no-datasource-refresh when new Item added to DataSource behavior that most of us (ouch) discover. The best way to fix this is just to use a 'BindingList [^] // create and initialize at class level scope: private...
12 Sep 2011 by bizzare1988
I have some items in a listbox, and when i click on the particular item, i need to enter the corresponding value in a text box, and these have to be saved in an xml. For example. my listbox contains name and age. I click on name, enter the corresponding value(say John) in the text box and i need...
12 Sep 2011 by bizzare1988
i have this now:private void Window_Loaded(object sender, RoutedEventArgs e) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlWriter writer = XmlWriter.Create("Query_advanced.xml", settings); ...
17 Oct 2011 by bizzare1988
Hi,I have a WPF window, which on the click of a run button, should expand in size and display my output grid. So far my code has been:
6 Nov 2011 by BlackJack99
Hi,I want to bind a list box to a List, and here is my xaml code of the listbox:
7 Nov 2011 by BlackJack99
seems like i did a pretty stupid mistake, i didn't put the accessor for the properties,solved, sorry for the problem.
26 Dec 2016 by BladeLogan
I have this project that I created the other day..It's a simple file sorter that get's the job done, sure the code is messy and looks horrible, So I was wonering.What can I do to make it look more professional?What should I have done different and what should I think about in the future...
31 Mar 2011 by BobJanova
If you inherit from UserControl you need to do everything yourself, including managing the list of items that are in the list box. For example, here is my control to solve a similar problem.
12 Aug 2011 by BobJanova
I think we need to see what is in '...'. The FileInfo object is clearly not getting cleaned up correctly and that might well be because you are storing a reference to it in the list (which you shouldn't). This is easy to do as both Image.FromStream and Image.FromFile keep the stream open and...
22 Mar 2010 by bobmoe1
How do I obtain a Code that creates a block that asks for First Name, Last Name,Email,Phone,Website,Social Medea ConnectionsAnd also ProvidesShare CodesThat I can use on any website, blog, splash page, facebook, twitter, linkedin, YouTube and all other social Media?
15 Dec 2015 by bojammis
Your code might work if all the list boxes had equal number of items. Consider this approach:Dim list As New List(Of ListBox)list.AddRange({ListBox1, ListBox2, ListBox3})For Each l As ListBox In list For Each s As String In l.Items ListBox4.Items.Add(s) ...
6 Aug 2013 by bowlturner
I am writing a sort/filter control for an application. What I would like is to use a list view to display the filter and to be able to add and remove lines from the filter. I'm still fairly new to WPF so I can believe I've made some obvious mistakes or missed something else that is...
12 Aug 2011 by BoxyBrown
If I got your question.(I still don't understand what is property ItemsSource for ListBox control and what is "bitmapimages")Try this one. if (isFirst) { listBox1.DataSource = null; listBox1.Items.Clear(); var...
5 Jul 2017 by BReinhart
First, I am using C++ Builder. I have a method in a class that loads a file into various structs. One of the fields in the struct is defined as, for example: typedef unsigned short namechar; struct MyStruct { int id; namechar name[32]; }; The code uses a for loop to go through all of the...
5 Jul 2017 by BReinhart
Ok, I got it to work. The solution I used is: for (int i = 0; i Items->Add(s); }
17 Oct 2010 by Brij
Its upto your design of database. You can store the data in multiple ways.One way , you can put the multiple rows according to the selection.Or you can also save it using some separator like comma in a single row.To get selected items Iterate all the items in listbox and find all the...
1 May 2012 by brinda p
hi...Try this.. public DelegateCommand RemoveUserCommand{ get; set; }RemoveUserCommand= new DelegateCommand(this.RemoveUser, this.RemoveUserExecute); private void RemoveUser() {//do struff}public bool RemoveUserExecute() { ...
1 May 2012 by brinda p
Hi,Try thishttps://github.com/mlaflamm/listbox-contextmenuHope this help Thanks..
2 Sep 2016 by C Amr Moneim
i want to select 1 row with 2 items from listbox to use them in method every 1min like exmplehere i add 2 items in 1 rowUniqueslist.Items.Add(string.Format("{0} , {1}", MobIDTextUnq.Text, MobCntTextUnq.Text));and i want to use this 2 items in this method every 1minpublic static...
2 Sep 2016 by C Amr Moneim
i want to select 1 row with 2 items from listbox to use them in method here i add 2 items in 1 row Uniqueslist.Items.Add(string.Format("{0} , {1}", MobIDTextUnq.Text, MobCntTextUnq.Text));and i want to use this 2 items in this method public static void Loadmonster(int...
28 Oct 2012 by Cagri Kaynar
try this code lbItemsList.BeginUpdate(); lbItemsList.DataSource = null; lbItemsList.DataSource = shoppingBasket.OrderItems; lbItemsList.EndUpdate();