Click here to Skip to main content
15,867,594 members
Everything / Combobox

Combobox

combobox

Great Reads

by Christoph Buenger
Describes PHP application development with the free Scavix Web Development Framework (Scavix-WDF).
by Nilay M Joshi
Multiselect Combobox - Custom control for WPF
by Johnny J.
A sample owner-drawn ComboBox
by Er. Puneet Goel
This tip implements the TreeView like DropDownList with Search Functionality using Telerik Kendo.

Latest Articles

by vblover Programmer
Custom DropDownBox with all languages of the world to select a language.Save and reload Selected language using Application Settings
by Nilay M Joshi
Multiselect Combobox - Custom control for WPF
by AXI_IeD
How to Filter contextually the list shown by a DataGridComboBoxCell?
by César Jaramillo L.
This is an alternative for "Embedding a DataGridView in a ComboBox"

All Articles

Sort by Score

Combobox 

31 Oct 2014 by Christoph Buenger
Describes PHP application development with the free Scavix Web Development Framework (Scavix-WDF).
26 May 2021 by Nilay M Joshi
Multiselect Combobox - Custom control for WPF
5 Jul 2013 by Johnny J.
A sample owner-drawn ComboBox
9 Jan 2015 by Er. Puneet Goel
This tip implements the TreeView like DropDownList with Search Functionality using Telerik Kendo.
30 Jun 2012 by OriginalGriff
It's not necessarily as simple as that - it depends to an extent on what type of items you have filled your ComboBox with. Because you can't just set the Items array (it exposes no public setter, just the getter) you have to create a new array of items, remove the duplicates, and set it back...
30 Jun 2012 by Sandeep Mewara
Why not just fetch the unique ones from database itself?Like:SELECT DISTINCT Names FROM MstNamesIf you still want to, before assigning the datasource, filter the datatable to be used. To know more of it, read here: MSDN: DataView.RowFilter Property[^]
10 Sep 2012 by JF2015
Here is some sample code:private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){ comboBox2.Items.Clear(); if (comboBox1.SelectedItem.ToString() == "1") { comboBox2.Items.Add("Hello"); comboBox2.Items.Add("World"); } else { ...
9 Jan 2019 by Graeme_Grant
Here is a MVVM solution that disables items in the other Combobox when a selection is made in one... First the Data Binding event plumbing base classes: public abstract class ObservableBase : INotifyPropertyChanged { public void Set(ref TValue field, TValue newValue, ...
20 Aug 2011 by Simon Bang Terkildsen
I would suggest you read Understanding the Visual Tree and Logical Tree in WPF[^] to understand the difference between the logical and visual tree.But in the case you describe here that is not needed, you can just do CriteriosOpcoesComboChecks.ItemsSource
10 Sep 2012 by Prasad_Kulkarni
If you are talking about cascading dropdownlist then have a look:Selecting value in cascading dropdown list dynamically[^]How to populate a dropdown list with another ddl[^]Cascading DropDown - Country to state[^]ASP.NET cascading drop-down-list...
10 Sep 2012 by Mohamed Mitwalli
Hi , Check this private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); using (SqlConnection Cn = new SqlConnection(Properties.Settings.Default.con)) { using (SqlCommand Cmd = new SqlCommand("SELECT * FROM ...
23 Apr 2013 by Sergey Alexandrovich Kryukov
You should use the property System.Windows.Forms.ComboBox.Text, which is the value currently presented in the edit area:http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.aspx[^],http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.text.aspx[^].—SA
15 May 2013 by CPallini
if (as you state in the remarks) no item is selected then cmbMode.SelectedItem is a null reference and you are not allowed to call its methods (like for instance cmbMode.SelectedItem.Equals) you may handle such a condition putting this line as the very first statement of your btnPredict_Click...
28 Jul 2013 by ridoy
Use..cmbCompName.Insert(0,"S...
12 Jun 2014 by Sergey Alexandrovich Kryukov
You cannot directly do it, because columns of the DataGridView are not controls. You can try to achieve desired effect by modifying the property Cursor of this control, depending on the current location of the mouse withing the control, using columns widths to calculate the location of each...
25 Mar 2015 by TarikHuber
Use STT (SQL Table Toolkit) to bind WinForm Controls to a DataGridview and to define ComboBox data sources
4 Feb 2016 by BillWoodruff
Why not use a 'Stack to save a certain number of the previous ComboBox selections ? This is a class I use to implement a fixed-size Stack of any Type:using System.Collections.Generic;namespace StackAndQueueUtilityClasses{ public class StackT : Stack { private int...
3 Oct 2017 by Blutfaust
Try this With UserForm1 For i = 2017 To 1960 Step -1 .ComboBoxYear.AddItem (i) Next End With
22 Nov 2009 by likhein
How do I highlight or display some text like "select item" or "select name" in a combobox in a light gray color in such a way that whenever I click anywhere on the combobox, the text should be cleared and the drop down list opens?
15 Sep 2010 by William Winner
First of all, how in the world are you setting ComboBox.SelectedIndex to null?It is an int variable which is a non-nullable type.If you're setting it to null, then that's your problem.And if you're setting it to -1 and then getting an error in your SelectedIndex_Changed event, then...
16 Sep 2010 by Marc A. Brown
Is there a typo in your if statement that opens comboBox!_SelectedIndexChanged? You've got comboBox1.SelectedValue1=null and I'm thinking it should be comboBox1.SelectedValue!=null.
16 Sep 2010 by William Winner
First, I hope this is not another typo, but you have:if ((isClosing == false)&&(comboBox1.SelectedValue=null))Without the double equal sign, comboBox1.SelectedValue will be set to null.That would result in your call String cb1Value = comboBox1.SelectedValue.ToString(); raising an...
16 Sep 2010 by Bardy85
I think the following is more or less what you are looking for.public Form1() { InitializeComponent(); FillFirstCombobox(); cmbSecond.SelectedIndexChanged += new EventHandler(cmbSecond_SelectedIndexChanged); } private void...
13 Dec 2010 by Hiren solanki
That could be the right way but I haven't used the same anytime.You could also try to bind it using this alternate way.cboField1.DataSource = Orders2 ;cboField1.DisplayMember = //Name of fields to be displayed.cboField1.ValueMember = //Name of field to be kept as value.Please vote...
7 Jan 2011 by Sandeep Mewara
As much as I remmeber, it should be mycombobox.SelectedIndex = -1; Have a look at this article[^].
9 Mar 2011 by Tarun.K.S
Here are few links which can help you make a Custom...
8 Sep 2011 by Ian Landicho
A simple combo box that will have predefined items but the selected value bound to a property from our View Model.
14 May 2012 by Wendelius
You can use the ComboBox.SelectedItem Property [^] to fetch the item that is currently selected in your comnbo box.Since you're using a datatable, the item itself should be a DataRowView. So you can reference the value using the Item[^] property.So something like:if...
15 May 2012 by VJ Reddy
The answer for the update to question: Is there anyone out there who can help me in reading the values from valuemember of combobox. can be as follows:The SelectedValue property of ComboBox can be used to obtain the object containing the value of the member of the data source specified by...
16 Aug 2012 by I.explore.code
1) Limit the number of elements shown in the combo box, otherwise it would defeat the usability of the control if the user has to browse through all that data to get to the item they want. For limiting data, you can try loading 5 items or 10 items at a time and when the user scrolls past the...
16 Aug 2012 by Santhosh Kumar Jayaraman
Why do you want to display 20000 records in Combobox?? Do you think user will be scrolling down and check 20000 records to select one record?Try something else like autocomplete textbox or gridview with paging.its very bad idea to load 20k records in a combobox.. Even if we make some...
6 Dec 2012 by OriginalGriff
When you start your program, the combo box is filled with the items you specify in the designer. If you want to have other items (say that are saved on program exit and loaded again on start up) then you have to save them somewhere and restore them yourself in the code.The easiest way to do...
24 May 2013 by OriginalGriff
Try:private void myComboBox_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cb = sender as ComboBox; if (cb != null) { ... } }
27 Aug 2013 by Sergey Alexandrovich Kryukov
You are doing a wrong thing with SelectedItem, wrong in principle. You don't have to store strings in a combo box or a list box. You can store any objects. That way, you will avoid unsupportable, inefficient and unreliable parsing of the item's text to integer or anything else. Instead, you...
1 Jan 2014 by CHill60
You have several issues with your attempts. Most importantly you are trying to mix numeric data and string data. Sometimes you will get an implicit conversion done "for you" but you should never rely on this.In your second attempt you are confusing SelectedIndex (the rank of the selected...
16 Jan 2014 by Codes Of Shadows
Header Style Combo Box Drop Down Filter Button
27 Mar 2014 by BillWoodruff
If you are willing to do the work to create a UserControl, you can combine a ListView, which supports Groups, with a TextBox, for displaying the selected List Item. It's actually pretty easy to do, but, if you are relatively new to C# and Windows Forms, and have no experience with UserControls,...
9 Oct 2014 by BillWoodruff
I'd advise you not to use the solution in the link in production code: the architecture is seriously flawed; it uses a Form as an internal part of a Control that inherits from ComboBox which is like shooting a mouse with a cannon.If you have to use that code, then why not just put another...
17 Nov 2014 by ZurdoDev
It actually is pretty easy as you expect. There are different ways. You can add the option to your Data Source or you can just add it manually.Some good examples are here: http://stackoverflow.com/questions/5134152/add-an-item-to-combobox-before-bind-data-from-data-base[^]
5 May 2015 by CHill60
See solution 1 on this post - Multi Selection inside a combo box!!![^] and this CP article CheckBox ComboBox Extending the ComboBox Class and Its Items[^]
5 May 2015 by Sascha Lefèvre
The standard ComboBox doesn't offer the functionality of CheckBoxes. You need to either build your own custom control or search for an available solution. Here are two Codeproject-articles presenting solutions for this:CheckBox ComboBox Extending the ComboBox Class and Its Items[^]A...
29 Sep 2015 by Wendelius
When you loop through the items in a combo box you actually loop through the objects assigned to the combobox using the ItemsSource property. For example if the items source is a data view your loop would iterate through the datarow objects from the view. So when you call the ToString method...
3 Jun 2016 by César Jaramillo L.
This is an alternative for "Embedding a DataGridView in a ComboBox"
7 Dec 2016 by OriginalGriff
Do two things:1) Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.2) Use the debugger to follow exactly what is happening with your code. Put a...
24 Feb 2017 by Karthik_Mahalingam
try using SQl Data Adapter[^] private void cbPlan_Click(object sender, EventArgs e) { cbPlan.Items.Clear(); string pullsub = "select PlanID,PlanName from fbkPlanMaster(nolock)"; string connString =...
11 Nov 2017 by FranzBe
You are assigning the .Text property of the combobox (i.e. the DisplayMember) to the @auID parameter that goes to tblBookDetail.authorId; cmd.Parameters.Add("@auID", SqlDbType.VarChar).Value = cmbAuthor.Text what you want to assign is the numeric Id of the author that is in the ValueMember....
18 May 2019 by Patrice T
Quote: When I select a value from customer no. Combo box, it does not display name in text box. You need to run your code under debugger to detect where is the problem because the try-catch block prevent any error message. What happen when no record match the query? Wilde guess Dim C2_Qry As...
2 Oct 2019 by Maciej Los
Wel... Start here: Ready-to-use serial port enumeration list box[^] For further details, please see: SerialPort.GetPortNames Method (System.IO.Ports) | Microsoft Docs[^] [EDIT] There's no guarantee that SerialPort.GetPortNames method will return the names of ports. But, there's work-around....
17 May 2020 by Maciej Los
You're using DisplayMember[^] and ValueMember[^] properties wrong way. In both cases the description is: MSDN wrote: A String specifying the name of an object property that is contained in the collection specified by the DataSource property. The...
14 Sep 2020 by BillWoodruff
I'm not going to write our code for you, but, I hope I can give you some ideas: 1 to fill the ComboBox with a set of nom duplicate items: // dt is the DataTable // c2 is the #2 DataColumn var cval = dt.AsEnumerable().Select(row =>...
16 Jan 2022 by Luc Pattyn
Hi, your ComboBox3.SelectedIndex = i is not doing anything useful. Your Dim parsedate As DateTime = ComboBox2.SelectedItem.ToString will give the same result on each iteration of your loop, and all items in ComboBox3 will end up showing the...
1 Apr 2022 by TheRealSteveJudge
If ArcGIS is using WPF then you must change your code like this:Application.Current.Dispatcher.Invoke(() => { comboBox.Items.Add(name); }); BTW: WPF is different from Windows Forms! Please read this: Difference between WPF and WinForms -...
6 Sep 2023 by OriginalGriff
We can't tell, we have no access to your code while it is running, so we have no idea what is in m_RadIsntExist or what it should contain. So, it's going to be up to you. Fortunately, you have a tool available to you which will help you find out...
10 Dec 2009 by nGrafix
Hi guys,I finished my project in VB.NET (VS.NET 2008). This project supports three languages; English (UK), Kazakh (Kazakstan) and Hausa (Nigeria). The program allows the user to swtich between the languages at runtime via ComboBox's SelectedIndexChanged event.The problem is Hausa (a...
10 Dec 2009 by MaasOne
Check the Windows version from System.Environment-class. Vista has version 6 and Win 7 has (what a surprise :)) version 7. Private Function IsVistaOrHigher() As Boolean Return Environment.OSVersion.Version.Major >= 6 End FunctionMaas
12 May 2010 by Abhinav S
Have a look at this post.Once you have implemented an event for key stroke, you can write logic to refresh your UI based on this stroke.
4 Aug 2010 by Kim Togo
Take a look at ComboBox.TextUpdatePerhaps this can helpComboBox.TextUpdate
15 Sep 2010 by Marc A. Brown
Check the value of SelectedIndex and skip over the code that errors if it's null or -1.
15 Sep 2010 by Marc A. Brown
Alternatively, create a form level boolean to indicate that the form is closing and set it to true in the form's closing event. Then only run the code in your combo box's changed event handler if that variable is false.
16 Sep 2010 by Abhishek Sur
You can set SelectedIndex = -1, but always remind you that when you set it to -1 even though one item will seem to be selected, you cannot get its value from SelectedItem as it will return you null.Please check SelectedItem to be null before calling any method. :rose:
8 Jan 2011 by fjdiewornncalwe
Are you writing WinForms/WPF/Web???In any case. Make sure your code for .SelectedIndex = 0 is actually firing where you expect it to and that it isn't being overriden by another assignment somewhere else because the statement will work if it is used in the right place.--Edit:Based on the...
22 Jan 2011 by Henry Minute
If your ComboBox is part of a ComboBoxColumn then Manfred's solution might not work.Take a look at this[^] thread on MSDN.Social (Scroll down until you see the first message from 'mcassoc') and in that message take note of the event handler for the EditingControlShowing event. Using that...
19 Jan 2011 by Espen Harlinn
A bit hard to understand what you actually want here, but it kind of sounds like filtering, so here is a nice article on the subject:DataGridView Filter Popup[^]It's just a guess, hope it helps you out :)RegardsEspen Harlinn
10 Feb 2011 by #realJSOP
Try this:ta = cbxGenre.SelectedText;Have you considered using the debugger?
29 Mar 2011 by 3-Sigma
If I have a dropdown style combobox, and I type in a value which isn't in the list but matches the start of a value in the list, then that value gets selected when I click the dropdown arrow. Eg If I type in 13, and 130 is in the list, then 130 is selected if I click the dropwdown arrow. Is...
1 Jun 2011 by Marrakech
HiTo Do this:1. In Windows Forms designer go to combobox properties.2. Find datasource property and expand it3. Click "Add new Project datasource".4. In the wizard select Object and then Next.5. Select Person class in the tree ( if you does not have it try to build project with...
1 Jun 2011 by Wayne Gaylard
Try this wayList person = new List() { new Person(){Name="Anna", Birthday=new DateTime(2006, 10, 01), Age=12}, new Person(){Name="Ben", Birthday=new DateTime(2006, 11, 02), Age=13}, new Person(){Name="Cora",...
15 Aug 2011 by Coder Block
Hello All, I Have little application to drawn different different shapes on client area of window in mfc. Type of shape is selected from toolbar.A shape toolbar is dynamically created depends on the number of images present in "\drawShapes\Img\*" folder.That is if i...
16 Aug 2011 by enhzflep
Something like this perhaps?Toolbars with embedded Combo Boxes[^]
23 Sep 2011 by AnilBaviskar
Hello All,I am facing difficulty in below situation:I have WPF datagrid with few columns. I want to show/hide certaincolumns based on combobox selection change.I tried using StaticResources, ObjectDataSource etc options but no use.What collection I should use & how the binding...
28 Sep 2011 by Pradeep Shukla
First you should not store the "Category Desc" in tblProduct, use the CategoryID instead. As far as the question of filling up the combo box...Use a SQL query like this : SELECT NAME, CATEGORYID FROM TBLCATEGORYuse this to fetch the data and bind the combo box with the datatable.set the...
31 Dec 2011 by OriginalGriff
Rather than rely on objects, in C# it is considered good practice to use explicit objects. For example:public class MyItem { public string String { get; set; } public int Int { get; set; } public MyItem(string s, int i) { String = s; Int = i; } public override string...
20 Feb 2012 by SteveAdey
In your ViewModel define a property like:public IEnumerable Names{get{ return nameColumn.Split('|');}}Then bind your ComboBox ItemsSource to NamesOk, the ViewModel will look like: public class MainViewModel { private string...
26 Feb 2012 by Shahin Khorshidnia
HelloIf you want to keep the previous item: //DataRowView rw = (DataRowView) ownerComboBox.SelectedItem;object selectedItem =...
2 Oct 2012 by wkiess01
How to sort a data bound combobox
12 Jun 2012 by Dave Kreskowiak
Ask your question at the bottom of Marc's article, here[^].
23 Jun 2012 by wolfsor
private void GetSupplierName() { try { cbosupplier.Items.Clear(); string query = "Select distinct SupplierName from Supplier" + " order by SupplierName asc"; SqlCommand cmd = new...
18 Jul 2012 by Sunny_Kumar_
Hi,set DoubleBuffered property of the form to True on Form_Load.this.DoubleBuffered = true;This will remove the flickering.Hope this helps.Happy Coding :)
5 Aug 2012 by AshishChaudha
Find out your solution from previous solution..please refer to the following linkConnectivity of Dropdown lists with two tables of SQL[^]thanksAshish
5 Aug 2012 by Christian Graus
You select the data from your database, then make that the data source of your combo box. Your question is so vague, I am guessing that you're using a .NET language and not PASCAL or something.
10 Aug 2012 by Philip Stuyck
KnownColor, that enumeration is very specific to WinForms, not a good idea to mix different color definitions of two different technologies unless you really have to which is not the case here.Another thing is that in code you have to convert the color to a solid brush, since our are referring...
16 Aug 2012 by AmitGajjar
Hi,You can add your custom control in your page. That custom control should have features like,1) Paging for 10/20 records a page.2) page should be navigate through Next/Previous/First/Last/Goto.3) You need Searching in your custom Combobox.Here[^] some basic idea about Custom...
17 Aug 2012 by Kenneth Haugland
There is only onw thing to do in such a case, you will have to use an IValueConverter:Data Binding Using IValueConverter in Silverlight[^]You could bind the second combobox to isenabled and do the appropiate convertions from the selected values of the second one :)
24 Jun 2021 by joshrduncan2012
Can anyone help me with how to populate a combobox with data once another combobox has been selected? I'm confused as to how the selectedindexchanged events work. I am using C# with Visual Studio 2010/2012.
20 Sep 2012 by dbaseman
The problem is that you're attempting to modify the control before it has been initialized. To get it to work all you have to do is have the constructor inherit from the base class: public customcombobox() : base() { Binding binding = new Binding(); ...
20 Sep 2012 by Member 9346729
I figured out my problem. Didn't need to have the constructor inherit from the base it said it was redundant. The problem was actually in my converter. I use the same converter elsewhere in my code but when using it in the xaml it doesn't send it as a list it sends each individual item in the...
23 Oct 2012 by Braj_12
Change the property DropDownStyle as DropDownList then user can not edit items from Combo box.
2 Nov 2012 by YvesDaoust
As a workaround, you can bind an auxiliary TextBox to the ComboBox so that it reflects the text. Then attach your handler to the TextBox TextChanged event and make the TextBox invisible.
2 Nov 2012 by Clifford Nelson
It appears not: http://www.go4answers.com/Example/comboboxs-textchanged-event-60975.aspx[^].
27 Feb 2013 by Vinoth Kumar J
Hi Kishore,As i have refered from the Extended Toolkit CheckCombox Style the arrow syle is look as belowM 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3...
2 Mar 2013 by Joezer BH
You can convert the datatable of string that you use as input to an array of strings, that should sort out the behavior. It has nothing to do with the centering. When this line:txt = this.Items[e.Index].ToString();gets a DataRowView as input, then the ToString method will of course...
21 Mar 2013 by Irina Pykhova
try this one: M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3...
15 Apr 2013 by Maciej Los
There are 3 ways:1) using OleDb objects and DataSource[^] property,2) using Excel.Interop,3) using CreateObject() function.Reading and Writing Excel using...
20 May 2013 by Johnny J.
You need to custom draw it - the standard ComboBox doesn't allow you to customize the appearance of the drop down list.This example might be of help to you:Appearance Customizable ComboBox[^]But I don't know if it even allows changes to the drop down list, or only to the textbox...
1 Jun 2013 by Basmeh Awad
try thisPrivate Sub cmbCustomerName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbCustomerName.Leave 'Code for fill datatable -removed here for easy reading cmbPlateNo.ValueMember = "car_id" cmbPlateNo.DisplayMember = "plate_no" ...
8 Jul 2013 by OriginalGriff
Probably not - but it's quite likely you are doing it at the wrong time.If you are doing it in the same code that you are loading the items into the combobox then it is very likely that the value will be zero because the items are not loaded from the XML file immediately - it waits until the...
25 Jul 2013 by Richard MacCutchan
You could start by looking at Creating Custom Controls[^], by our glorious leader.
28 Jul 2013 by Kuthuparakkal
Try this:if(cmbCompName.Items.Count > 0){ //You can set using SelectedIndex cmbCompName.SelectedIndex= 0;}