Put ligature char to a ComboBox text

Viewed 94

I use a ComboBox with DropDownStyle set to DropDown, meaning I can insert any text, independently from ComboBox's list DataSource.

I set the DataSource to:

comboBox.DataSource = new List<string> {"", "oe"};

If I set text with ligature:

comboBox.Text = "œ";

it is immediatelly changed to the oe form.

Text is normally set when ligature's normalization entry does not exist in data source.

How to force to not normalize this text?

1 Answers

You can use the SelectedText property instead of the Text property:

comboBox.Focus();
comboBox.SelectedText = "œ";

Setting the SelectedText value, implies sending (SendMessage) a EM_REPLACESEL message to the ComboBox's Edit control. This just substitutes the text in the Edit control: the control doesn't try to match the text entered to the elements in the list.

You could also reset the Text property, setting:

comboBox.Text = string.Empty;
comboBox.SelectedText = "œ";

In this case, setting the ComboBox.Text property raises the TextChanged event 3 times, when there's a previous selection, while setting the Focus (selecting the exiting text, if any) and replacing the selection, raises the event only once and only if the Text actually changes. It may be a relevant difference.

Setting the Text property, implies calling SetWindowText, which sends a WM_SETTEXT message. This will trigger the pattern matching feature, which will also cause, following the Unicode Standard 12.1.0 Case Folding Properties, a character normalization in the case matching procedure:

The data supports both implementations that require simple case foldings (where string lengths don't change), and implementations that allow full case folding (where string lengths may grow). Note that where they can be supported, the full case foldings are superior: for example, they allow "MASSE" and "Maße" to match.

Related