在Windows窗体中,是否可以在c#中的组合框中添加标签?

在Windows窗体中,是否可以在c#中的组合框中添加标签?,c#,winforms,combobox,C#,Winforms,Combobox,我有一个显示基础教育详细信息的组合框,分为三类:学士、文凭和学校教育。我需要给出这三个类别,因为每个标题都有不同的值。是否可以在c#中的windows窗体中执行此操作 您希望获得与显示的文本(学士、文凭和学校教育)不同的值,对吗 如果是,您可以按如下方式实施: namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { Initi

我有一个显示基础教育详细信息的组合框,分为三类:学士、文凭和学校教育。我需要给出这三个类别,因为每个标题都有不同的值。是否可以在c#中的windows窗体中执行此操作

您希望获得与显示的文本(学士、文凭和学校教育)不同的值,对吗

如果是,您可以按如下方式实施:

namespace WindowsFormsApplication1 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();

            comboBox1.Items.Add(new MyComboItem("Bachelor",0));
            comboBox1.Items.Add(new MyComboItem("Diploma", 1));
            comboBox1.Items.Add(new MyComboItem("Schooling", 2));
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
            if (comboBox1.SelectedIndex >= 0) {

                MyComboItem item = (MyComboItem)comboBox1.SelectedItem;
                MessageBox.Show("value of " + item.Text + " is : " + item.Value);
            }
        }
    }

    public class MyComboItem {

        private string text;
        private int value;

        public string Text { get { return this.text; } }
        public int Value { get { return this.value; } }

        public MyComboItem(string text, int value) {
            this.text = text;
            this.value = value;
        }

        public override string ToString() {
            return this.text;
        }


    }
}

你能再解释一下吗?一个图像示例会更有用。我想你需要类似于HTML中使用的optgroup标记的东西,对吗?但据我所知,您需要两个组合框,一个用于类别(学士学位、学校教育),另一个用于在选择此组合框的值后包含特定值。不确定WinForms是否可行,但使用WPF则相对容易。我不明白你想要什么。在组合框中,只有一列项目,没有标题。您可以绘制项目所有者并使分组项目突出,还可以防止它们被选中。。