megab16
megab16

Reputation: 23

C# Combobox Displaying Blank Items

I'm coding a combobox in C# and for some reason the items in the drop down don't have text. When I have selected an item, it is shown in the combo box text field (the drop down list is always blank whenever I click the drop down button). The datasource seems bound properly because the proper values are being returned when I select items, and the size of the drop down list will change depending on how many items the datasource has. Everything looks fine except for the fact that it seems like my drop down is populated with a bunch of empty strings, which it clearly isn't since as soon as an item is selected the proper text will display.

This is the relevant code:

if (list.Count > 0)
{
    cboCustomers.DisplayMember = "Name";
    cboCustomers.DataSource = list;                
    cboCustomers.ValueMember = "ID";                
    cboCustomers.SelectedIndex = 0;                
}

I have looked for an answer to this but can't find it anywhere...I'm sure it's something really simple, but I can't figure it out. The closest problem I found had an answer suggested to set the display member before the data source, which clearly didn't work.

The list is populated from a database query. This will run on keyUp, the idea is that the list is populated as the person is typing based on the info given. So if I wrote 'S' I'd get a combobox with a dropdown that had all the clients starting with 'S'.

Upvotes: 2

Views: 6944

Answers (2)

tinstaafl
tinstaafl

Reputation: 6958

as soon as an item is selected the proper text will display.

A foreground color the same as the background color will produce the same results you are seeing.

Upvotes: 2

dotNET
dotNET

Reputation: 35460

Given you don't have any anomalies in your binding, you are probably being affected by DrawMode property of your ComboBox, which may be set to OwnerDrawFixed or OwnerDrawVariable. Set it to Normal and things should get better.

Upvotes: 14

Related Questions