ComboBox默认数据绑定

界面

image

代码展示

        public FrmMain()
        {
            InitializeComponent();
            string[] portList = SerialPort.GetPortNames();
            if(portList.Length > 0) {
                this.cmb_Port.Items.AddRange(portList);
                this.cmb_Port.SelectedIndex = 0; 
            }

            for (int i = 1; i < 11; i++)
            {
                this.cmb_DevAdd.Items.Add(i);
            }
            this.cmb_DevAdd.SelectedIndex = 0;

            this.cmb_Lang.DataSource = new string[] { "简体中文", "English" };

        }
posted @ 2025-09-28 21:33  恨水长秋  阅读(16)  评论(0)    收藏  举报