티스토리 뷰

[조건]

- comboBox1에 데이터 바인딩 한다.

- 데이터 바인딩을 DataTable형으로 진행한다.


[최종 gif]

 

 


[코딩]

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 _222
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //임시데이터
            Dictionary<String, String> _DicSample = new Dictionary<string, string>();
            _DicSample.Add("0", "Apple");
            _DicSample.Add("1", "Pear");
            _DicSample.Add("2", "Orange");
            _DicSample.Add("3", "Banana");
            _DicSample.Add("4", "Cherry");


            DataTable table = new DataTable();
            table.Columns.Add("KEY", typeof(string));
            table.Columns.Add("VALUE", typeof(string));
            DataRow row;

            row = table.NewRow();
            row["KEY"] = "";
            row["VALUE"] = "전체";
            table.Rows.Add(row);

            foreach(KeyValuePair<string,string> item in _DicSample)
            {
                row = table.NewRow();
                row["KEY"] = item.Key;
                row["VALUE"] = item.Value;
                table.Rows.Add(row);
            }

            comboBox1.ValueMember = "KEY";
            comboBox1.DisplayMember = "VALUE"; //화면에 보이는 맴버
            comboBox1.DataSource = table;
        }
    }
}

'홈페이지 > C# 윈폼 & DevExpress' 카테고리의 다른 글

C# ?? / ?. 차이  (0) 2022.07.31
row 2줄  (0) 2021.11.09
C# 표안에 이미지 넣기  (0) 2021.11.01
C# 윈폼 comboBox 데이터 바인딩  (0) 2021.11.01
댓글