下拉框--可多選


方法 1:控件  checkedComboBoxEdit

///清空選項

 checkedComboBoxEdit1.Properties.Items.Clear();

///添加選項

checkedComboBoxEdit1.Properties.Items.Add("選項1-name", "選項1-description", CheckState.Checked, true);

 

方法 2:

 

 

        /// <summary>
        /// 點擊隱藏或顯示選擇框,並將所選內容顯示在bte_status中
        /// bte_status為輸入選擇控件(ButtonEdit)
        /// checkedListBoxControl1為控件(checkedListBoxControl)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bte_status_ButtonClick_1(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (this.checkedListBoxControl1.Visible.Equals(true))
            {
                this.checkedListBoxControl1.Visible = false;
                ///獲取選中的內容
                string output = string.Empty;
                for (int i = 0; i < checkedListBoxControl1.CheckedIndices.Count; i++)
                {
                    output += checkedListBoxControl1.Items[
                    checkedListBoxControl1.CheckedIndices[i]].ToString() + ",";
                }
                //去掉最后的,號
                if (output.Length > 0 && output.Substring(output.Length - 1).Equals(","))
                {
                    output = output.Substring(0,output.Length - 1);
                }
                this.bte_status.Text = output;
            }
            else
            {
                this.checkedListBoxControl1.Visible = true;
                string output = string.Empty;
                ///獲取選中的內容
                for (int i = 0; i < checkedListBoxControl1.CheckedIndices.Count; i++)
                {
                    output += checkedListBoxControl1.Items[
                    checkedListBoxControl1.CheckedIndices[i]].ToString() + ", ";
                }
                //去掉最后的,號
                if (output.Length > 0 && output.Substring(output.Length - 1).Equals(","))
                {
                    output = output.Substring(0, output.Length - 1);
                }
                this.bte_status.Text = output;
            }
        }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM