简体   繁体   中英

Combo box not showing items when it has focus

I have 2 combo boxes on a winform, both dragged onto the surface via the designer, both get their items from a database both connect to the dbase fine and are populated properly. But one of them, when it has focus, the selected item is not visible; all that can be seen is the blue background highlight. I have compared the properties of both and cannot discern any setting that is different and that might cause this. When the combobox loses focus the selected item is show, black foreground on a white background as would be expected.

Have a look at the data that is in the Display Member. This might end with blanks/white spaces. I had this same issue when the combobox was populated using a dataset from an SQL Database. After changeing the select statement to remove leading and trailing spaces it worked as expected.

The explanation for me: When editing/having focus, the combobox shows the text right-alligned in reverse video. If the text ends with a lot of blanks, as happens if you have SQL database with fixed length fields that are padded with spaces at the end, the result is that it shows the spaces at the end of the value (right alligned). If you remove the spaces in the select-query (in MSSQL this is done by ltrim(rtrim()) as the text of the selected item is not padded with spaces on the end, therefore it shows the text (in reverse video) until the focus is lost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM