Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for example:this is code into WPF aplication

string[] arrayMonth = new string[] { "January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"};

combobox.ItemsSource = arrayMonth;

What I have tried:

i want convert this code into c# Windown Form aplication, can you help me? thanks all
Posted
Updated 1-Mar-16 10:03am

Instead of .ItemsSource it's .DataSource for a WinForms-ComboBox:
C#
combobox.DataSource = arrayMonth;
 
Share this answer
 
Comments
Hoang Thang Vo 1-Mar-16 10:05am    
yes,thanks you so much
Sascha Lefèvre 1-Mar-16 10:59am    
You're welcome!
C#
using System.Globalization;
using System.Linq;

List<string> TheMonths = DateTimeFormatInfo.CurrentInfo.MonthNames.Take(12).ToList();
        
// in Form Load or somewhere
comboBox1.DataSource = TheMonths;

// use the combobox 

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    Console.WriteLine("{0}: {1}", comboBox1.SelectedIndex, comboBox1.SelectedValue);
}
Run code: observe.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900