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.