Prevent AutoSelect behavior of a System.Window.Forms.ComboBox (C#)

Try this: using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Windows.Forms; using Opulos.Core.Win32; namespace Opulos.Core.UI { // Extension class to disable the auto-select behavior when a combobox is in DropDown mode. public static class ComboBoxAutoSelectEx { public static void AutoSelectOff(this ComboBox combo) { Data.Register(combo); } public static void AutoSelectOn(this ComboBox combo) { Data data = null; … Read more

Interaction Triggers in Style in ResourceDictionary WPF

As far as I know, Interaction.Triggers can not be applied in Style, respectively and in a ResourceDictionary. But you can do so, to determine the ComboBox as a resource with x:Shared=”False” and reference it for ContentControl like this: <Window.Resources> <ComboBox x:Key=”MyComboBox” x:Shared=”False” ItemsSource=”{Binding Branches}” DisplayMemberPath=”BranchName” SelectedItem=”{Binding SelectedBranch}”> <i:Interaction.Triggers> <i:EventTrigger EventName=”SelectionChanged”> <i:InvokeCommandAction Command=”{Binding SelectCustomerCommand}” /> </i:EventTrigger> … Read more

insert item in combobox after binding it from a Dataset in c#

You have to Insert to the object you are databinding to rather than to the combobox. You can’t insert directly into the combobox. You can use this: DataTable dt = new DataTable(); dt.Columns.Add(“ID”, typeof(int)); dt.Columns.Add(“CategoryName”); DataRow dr = dt.NewRow(); dr[“CategoryName”] = “Select”; dr[“ID”] = 0; dt.Rows.InsertAt(dr, 0); cmbCategory.DisplayMember = “CategoryName”; cmbCategory.ValueMember = “ID”; cmbCategory.DataSource = … Read more

How do I bind a ComboBox so the displaymember is concat of 2 fields of source datatable?

The calculated column solution is probably the best one. But if you can’t alter the data table’s schema to add that, you can loop through the table and populate a new collection that will serve as the data source. var dict = new Dictionary<Guid, string>(); foreach (DataRow row in dt.Rows) { dict.Add(row[“GUID”], row[“Name”] + ” … Read more

Populating a ComboBox using C#

Define a class public class Language { public string Name { get; set; } public string Value { get; set; } } then… //Build a list var dataSource = new List<Language>(); dataSource.Add(new Language() { Name = “blah”, Value = “blah” }); dataSource.Add(new Language() { Name = “blah”, Value = “blah” }); dataSource.Add(new Language() { Name … Read more

Binding Combobox Using Dictionary as the Datasource

SortedDictionary<string, int> userCache = new SortedDictionary<string, int> { {“a”, 1}, {“b”, 2}, {“c”, 3} }; comboBox1.DataSource = new BindingSource(userCache, null); comboBox1.DisplayMember = “Key”; comboBox1.ValueMember = “Value”; But why are you setting the ValueMember to “Value”, shouldn’t it be bound to “Key” (and DisplayMember to “Value” as well)?