본문 바로가기
Winform

기본 combobox

by 캡틴노랑이 2020. 9. 4.
반응형

c#기본 combo box

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//아이템 추가 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<string, string="">)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;
</string,>
반응형

댓글