组合框后面的代码 [英] combobox code behind

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

问题描述

我需要知道如何将表的列绑定到Windows窗体中的组合框并以窗体加载方式显示...我不能使用智能标记,只能使用后面的代码.
感谢您的帮助.

I need to know how to bind a column of a table to a combobox in a windows form and display it in form load...i cant use the smart tag, only the code behind.
thank for your help.

推荐答案

SELECT [COULUMNNAME] FROM [TABLENAME]


添加一个组合框,然后将其DataSource属性设置为上述查询的结果,并将其displaymember属性设置为列名称.


Add a combo box then set its DataSource property to the result of the above query and set its displaymember property to the column name.

private void BindComboBox()
{
  comboBox1.DataSource = dataSet1.Tables["Suppliers"];
  comboBox1.DisplayMember = "ProductName";
}




供您参考:
http://msdn.microsoft.com/en-us/library/w67sdsex.aspx [ ^ ]




For your reference:
http://msdn.microsoft.com/en-us/library/w67sdsex.aspx[^]


尝试以下操作:


try this:


ddl.DataSource = Datasource
                ddl.DataValueField = Datavaluefield
                ddl.DataTextField = Datatextfield
                ddl.DataBind();




数据源-包含源(例如,从表中选择列1)

datavaluefield-值

datatextfield-文本

tknks,




datasource - contains the source(ex. select column1 from table)

datavaluefield - value

datatextfield - text

tknks,


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

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