简体   繁体   中英

Combobox has an extra member

So I'm using MetroCombobox and I'm trying populate it with abbreviated month names but I'm getting an extra member at the bottom of the list.

This is my code:

var months = System.Globalization.DateTimeFormatInfo.InvariantInfo.AbbreviatedMonthNames;
mcbxGreenCardMonth.DataSource = months;

I don't understand why is it generating an extra member! Can someone tell me why and how can i get rid of it?

DateTimeFormatInfo.MonthNames returns the 13th element of the array is an empty string.Try this,

var months = System.Globalization.DateTimeFormatInfo.InvariantInfo.AbbreviatedMonthNames;
comboBox1.DataSource = months.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();

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