ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • C# ComboBox 아이템 추가
    닷넷/WinForms 2016. 7. 5. 13:48
    반응형

    1. Class 추가 (ComboBoxItem.cs 만들어서 아래의 코드 추가하기)

            public class ComboBoxItem
            {
                public string Text { get; set; }
                public object Value { get; set; }
                public override string ToString()
                {
                    return Text;
                }
            }

    2.

            void _ComboBoxItem()
            {
                ComboBox cbx = new ComboBox();
                cbx.DisplayMember = "Text";
                cbx.ValueMember = "Value";

                List<ComboBoxItem> list = new List<ComboBoxItem>();

                ComboBoxItem item = new ComboBoxItem();
                item.Text = "";
                item.Value = "";
                list.Add(item);

                item = new ComboBoxItem(); 
                item.Text = "이름";
                item.Value = "1";
                list.Add(item);

                item = new ComboBoxItem();           
                item.Text = "부서";
                item.Value = "2";
                list.Add(item);

                item = new ComboBoxItem();
                item.Text = "회사";
                item.Value = "3";
                list.Add(item);

                comboBox1.DataSource = list;
            }

     

    반응형

    댓글

Designed by Tistory.