1、添加下拉框的值:
comboBoxEdit1.Properties.Items.Add("12");
2、獲取選中下拉框的值:
控件事件SelectedIndexChanged下,添加comboBoxEdit1.SelectedIndex.ToString();
3、獲取選中下拉框的值:
comboBoxEdit1.Properties.Items[comboBoxEdit1.SelectedIndex].ToString();
完整代碼示例和結果如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ComboBoxEdit
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Init();
}
private void Init()
{
comboBoxEdit1.Properties.Items.Add("12");//添加下拉框的值
comboBoxEdit1.Properties.Items.Add("13");
comboBoxEdit1.Properties.Items.Add("14");
comboBoxEdit1.Properties.Items.Add("15");
}
private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
{
string str;
//str = comboBoxEdit1.Properties.Items[comboBoxEdit1.SelectedIndex].ToString();//獲取選中值的值
str = comboBoxEdit1.SelectedIndex.ToString();//獲取選中值的索引值
textEdit1.Text = str;
}
}
}