Winform
기본 combobox
캡틴노랑이
2020. 9. 4. 13:17
반응형
c#기본 combo box
//아이템 추가 1 cboPriorty.DisplayMember = "Value"; cboPriorty.ValueMember = "Key"; cboPriorty.Items.Add(new { Value = "high", Key = "high" }); cboPriorty.Items.Add(new { Value = "normal", Key = "normal" }); string value = (cboPriorty.SelectedItem as dynamic).Value; //아이템 추가 2 cboTest.DisplayMember = "Value"; cboTest.ValueMember = "Key"; Dictionary<string, string>dic = new Dictionary<string, string>(); dic.Add("1", "11111"); dic.Add("2", "22222"); dic.Add("3", "33333"); cboTest.DataSource = items; //cboTest.DataSource = new BindingSource(dic, null); string value = ((KeyValuePair)cboTest.SelectedItem).Value; //아이템 추가 3 cboTest.DisplayMember = "Text"; cboTest.ValueMember = "Value"; var items = new[] { new { Text = "report A", Value = "reportA" }, new { Text = "report B", Value = "reportB" }, new { Text = "report C", Value = "reportC" }, new { Text = "report D", Value = "reportD" }, new { Text = "report E", Value = "reportE" } }; cboTest.DataSource = items;
반응형