WPF IsEditable=true ComboBox filled with objects displays the ToString() as the selected item

You can do this entirely within Xaml <ComboBox IsTextSearchEnabled=”True” IsEditable=”True” ItemsSource=”{Binding MyObjectCollection}” TextSearch.TextPath=”MyObjectName”> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text=”{Binding MyObjectName}” /> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> The upside is that you can define and change this however you want in your XAML without any code-behind. You bind the ItemsSource to your collection of objects, and then you set the … Read more

Binding a ComboBox to an enum nested in a class

Another way of getting the enum values for use as a data source: <Window.Resources> <ObjectDataProvider MethodName=”GetValues” ObjectType=”{x:Type sys:Enum}” x:Key=”TestValues”> <ObjectDataProvider.MethodParameters> <w:Type2 TypeName=”w:Test+TestEnum” /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources> … ItemsSource=”{Binding Source={StaticResource TestValues}}” Note that you still need the Type2Extension because of weirdness with TypeExtension and nested types. But you wouldn’t need the extra custom markup extension. This … Read more

Change ComboBox Border Color in Windows Forms

You can inherit from ComboBox and override WndProc and handle WM_PAINT message and draw border for your combo box: using System; using System.Drawing; using System.Windows.Forms; public class FlatCombo : ComboBox { private const int WM_PAINT = 0xF; private int buttonWidth = SystemInformation.HorizontalScrollBarArrowWidth; Color borderColor = Color.Blue; public Color BorderColor { get { return borderColor; } … Read more

ComboBox.ValueMember and DisplayMember

You should not set datasource of your listbox and/or combobox in this order ComboBox1.DataSource = dataTable; ComboBox1.ValueMember = “id”; ComboBox1.DisplayMember = “name”; Instead, this is correct order: ComboBox1.ValueMember = “id”; ComboBox1.DisplayMember = “name”; ComboBox1.DataSource = dataTable; NOTE: setting datasource should be last line. If you set datasource first, SelectedIndexChanged event will fire and you may … Read more

Autocomplete combobox for WPF

After a lot of fiddling, I have managed to arrive at a complete, working solution. (Or so it seems.) Step 1. Modify XAML markup You need to modify your ComboBox like so: <ComboBox … IsTextSearchEnabled=”False” … PreviewTextInput=”PreviewTextInput_EnhanceComboSearch” PreviewKeyUp=”PreviewKeyUp_EnhanceComboSearch” DataObject.Pasting=”Pasting_EnhanceComboSearch” /> ie. to disable default text search, and add events handlers that will take care of … Read more

JavaFX – Filtered ComboBox

As far as the filtering of the drop down is concerned. Isn’t wrapping the list of possible options in a FilteredList the best solution? MCVE: import javafx.application.Application; import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.scene.Scene; import javafx.scene.control.ComboBox; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class MCVE extends Application { public void start(Stage stage) … Read more

ComboBox AutoComplete on SubString

Here is the C# version. It has a lot of options to it. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { this.Load += new EventHandler(this.Form1_Load); InitializeComponent(); } private clsCustomAutoCompleteTextbox ClsCustomAutoCompleteTextbox1 = null; private List<string> … Read more

How to populate c# windows forms combobox?

Below are the important properties for you. ComboBox.DataSource Property A data source can be a database, a Web service, or an object that can later be used to generate data-bound controls. When the DataSource property is set, the items collection cannot be modified. ComboBox.DisplayMember Property A String specifying the name of an object property that … Read more