Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'.

like image 972
megab16 Avatar asked Dec 29 '25 17:12

megab16


1 Answers

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.

like image 61
dotNET Avatar answered Jan 01 '26 08:01

dotNET



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!