Printer is a value type (thus the ? to make this Nullable<Printer> behind the scenes. Meanwhile, Item is a type that implements INotifyPropertyChanged and boils down to (it properly implements INotifyPropertyChanged for the SelectedPrinter property, I'm omitting here for brevity):

class Item
{
Printer? SelectedPrinter { get; set; }
}

The problem is, when I add this ComboBox to a form and show the form, the first printer from the list of available printers is automatically selected. I would like the combobox to respect whatever the initial SelectedPrinter property value is, whether it's null for no selection, or contains a printer selection of some sort.

I've attempted manually setting the combobox.SelectedValue both before and after the ComboBox is added to the control hierarchy, to no avail. Any suggestions?

1 Answer
1

If I understand you, the only problem you're having is that when the selected printer is null, it's auto-selecting the first printer in the list if the selected printer is null? That's expected behaviour as far as I can recall.

What you can do is check to see if the selected printer is null and then set the combobox's SelectedIndex to -1. Otherwise, you may have to create a null object and seed it into the datasource.