DEV ComboBoxEdit 控件之添加值,获得选中值

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;
}
}

}

posted @ 2020-03-12 14:11  向前追起  阅读(1380)  评论(0编辑  收藏  举报