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

Editable ComboBox with binding to value not in list

I was just doing this yesterday and today and it looks like the following: set the combobox IsEditable=”true” instead of binding to SelectedItem, bind to the Text property of the combobox if you’re binding to a custom object instead of just strings, you need to also set TextSearch.TextPath=”NameOfField”. This lets the text search behavior work, … Read more

JavaFX ComboBox change value causes IndexOutOfBoundsException

In JavaFX, you cannot change the contents of an ObservableList while a change is already in progress. What is happening here is that your listeners (any of the ones you try) are being fired as part of the box.getSelctionModel().getSelectedItems() ObservableList changing. So basically, you cannot change the selection while a selection change is being processed. … Read more

WPF: How to customize SelectionBoxItem in ComboBox

I would do it like this: <Window.Resources> <DataTemplate x:Key=”NormalItemTemplate” …> … </DataTemplate> <DataTemplate x:Key=”SelectionBoxTemplate” …> … </DataTemplate> <DataTemplate x:Key=”CombinedTemplate”> <ContentPresenter x:Name=”Presenter” Content=”{Binding}” ContentTemplate=”{StaticResource NormalItemTemplate}” /> <DataTemplate.Triggers> <DataTrigger Binding=”{Binding RelativeSource={RelativeSource FindAncestor,ComboBoxItem,1}}” Value=”{x:Null}”> <Setter TargetName=”Presenter” Property=”ContentTemplate” Value=”{StaticResource SelectionBoxTemplate}” /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> </Window.Resources> … <ComboBox ItemTemplate=”{StaticResource CombinedTemplate}” ItemsSource=”…” … /> The reason this works is that CombinedTemplate … Read more

What event catches a change of value in a combobox in a DataGridViewCell?

The above answer led me down the primrose path for awhile. It does not work as it causes multiple events to fire and just keeps adding events. The problem is that the above catches the DataGridViewEditingControlShowingEvent and it does not catch the value changed. So it will fire every time you focus then leave the … Read more

How can I dynamically change auto complete entries in a C# combobox or textbox?

I had the same problem, and found an extremely simple workaround. As everybody else here, I couldn’t find any means to control de behaviour of the component, so I had to accept it. The natural behaviour is: you can’t dynamically populate the list every time the user types into the text box. You have to … Read more

Raise an event when I hover the mouse over a ComboBox item

You can create a Custom Control, derived from ComboBox, override its WndProc method to intercept the CB_GETCURSEL message. Call base.WndProc(ref m) first. When the message is processed, the Message object’s m.Result property is set to a value (as IntPtr) that represents the Item currently tracked in the ListBox (the Item highlighted when the Mouse Pointer … Read more