将项目添加到组合框 [英] Add Items to the ComboBox

查看:155
本文介绍了将项目添加到组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ComboBox 控件。

我将此控件绑定到DataSet表。

I bind to this control to the DataSet table.

这是代码:

comboBox.Items.Add(("Select"));
comboBox.DataSource = DataSet.ColorTable;
comboBox.DisplayMember = DataSet.ColorTable.ColorNameColumn.ColumnName;
comboBox.ValueMember = DataSet.ColorTable.ColorIDColumn.ColumnName;

我得到的结果是:

< img src = https://i.stack.imgur.com/8w1pY.png alt =在此处输入图片描述>

我想在列表顶部的 SELECT:字词。因此,我需要将额外的Item添加到comboBox控件中。
这是我的实现方式:

I want to display on the top of the list SELECT: word. So I need to add addition Item to the comboBox control. Here how I implement it:

cmbCategory.Items.Add(("Select"));

但是结果仍然与上面相同。我只得到列表顶部没有 SELECT:单词的颜色。

But the result is still the same as above. I get only colors without SELECT: word on the top of the list.

任何想法如何添加此字符串- SELECT :到ComboBox控件并设置为此字符串 ValueMember

Any idea how I can add this string-SELECT: to the ComboBox control and set to this string ValueMember?

推荐答案

您可以将颜色集合添加到数组数据集中(如果要从中获取它们)数据库),然后添加选择项,然后添加数组的每个元素或数据集的列。

You can add the collections of color to an array or a dataset (if you are getting them from database) first and then add items "select", then add each elements of the array or a column of the dataset.

Form_Load 函数以及任何在颜色集合数组或数据库中进行了更改的地方执行此操作。

Do this in Form_Load function and wherever there are changes made in color collections array or database.

这篇关于将项目添加到组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆