using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ComboBoxControl
{
	public enum CTR_CODE
	{
		kor,
		bri,
		jpn,
		chn,
		ind,
		frc,
		ger,
		ita,
	}

	public partial class Form1 : Form
	{
		private List<Country> dataSource;

		public Form1()
		{
			InitializeComponent();

			InitInstance();
		}

		private void InitInstance()
		{
			dataSource = new List<Country>();
			dataSource.Add(new Country() { Name = "한국", Code = CTR_CODE.kor});
			dataSource.Add(new Country() { Name = "영국", Code = CTR_CODE.bri });
			dataSource.Add(new Country() { Name = "일본", Code = CTR_CODE.jpn });
			dataSource.Add(new Country() { Name = "중국", Code = CTR_CODE.chn });
			dataSource.Add(new Country() { Name = "인도", Code = CTR_CODE.ind });
			dataSource.Add(new Country() { Name = "프랑스", Code = CTR_CODE.frc });
			dataSource.Add(new Country() { Name = "독일", Code = CTR_CODE.ger });
			dataSource.Add(new Country() { Name = "이탈리아", Code = CTR_CODE.ita });

			comboBox.DataSource = dataSource;
			comboBox.DisplayMember = "Name";
			comboBox.ValueMember = "Code";

			comboBox.SelectedIndex = -1;
		}

		public class Country
		{
			public string Name { get; set; } = "Country";
			public CTR_CODE Code { get; set; }
		}

		private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
		{
			Country selected = comboBox.SelectedItem as Country;
			if (selected == null)
				return;

			Console.WriteLine($"selected: Name {selected.Name}, Value {selected.Code.ToString()}");
		}
	}
}
