CodeMonkey
CodeMonkey

Reputation: 2523

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?

Upvotes: 0

Views: 21

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222657

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();

Upvotes: 1

Related Questions