Winforms ComboBox Text & Value example

the really simple way, and goes for the rest of the winform controls
you could also put a list of any class and choose 2 properties

DataTable tblMonths = new DataTable();
tblMonths.Columns.Add(new DataColumn("Name", typeof(string)));
tblMonths.Columns.Add(new DataColumn("Value", typeof(int)));
for (int i = 1; i <= 12; i++)
    string month = DateTimeFormatInfo.CurrentInfo.GetMonthName(i);
    new object[] { month, i });
cmbMonths.DataSource = tblMonths;
cmbMonths.ValueMember = "Value";

cmbMonths.DisplayMember = "Name";
cmbMonths.SelectedValue =


Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

Asp.Net Ending Response options, Response.End() vs CompleteRequest()

JS/JQ simulate Enter event