填充以编程方式制作的组合框(不在设计器中) [英] Populate a programmatically made combobox(not in designer)
本文介绍了填充以编程方式制作的组合框(不在设计器中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想问你是否知道如何填充编程组合的组合框。我在编程方面的意思是它不在设计师中。这意味着很多。
谢谢! :)
解决方案
或者您可以设置组合框的数据源并直接从数据表填充它,例如:
cbCountry.DataSource = CustomSQL.GetCountryList
cbCountry.DisplayMember = Country
cbCountry.ValueMember = Country
cbCountry.Text = cbCountry.Items( 226 )。ToString
此示例使用从CustomSQL.GetCountryList返回的数据表中的国家列表填充组合框,然后预选英国(列表中的项目226)作为文本。
你有什么试图得到你的答案?我什么都没假......因为这是一个非常基本的任务。
参见: http://msdn.microsoft.com/en-us/library/system.windows.forms。 combobox.items.aspx?cs-save-lang = 1& cs-lang = vb#code-snippet-2 [ ^ ]
你填充它调用Items
属性的Add
方法,例如
myComboBox.Items.Add( 第一项跨度>)
Hi All,
I would like to ask if you know how to populate a programatically made combobox. What I mean in programatically is that it is not in the designer. It will mean a lot.
Thank you! :)
解决方案
Or you can set the Datasource of the combobox and populate it directly from a datatable, for example:
cbCountry.DataSource = CustomSQL.GetCountryList cbCountry.DisplayMember = "Country" cbCountry.ValueMember = "Country" cbCountry.Text = cbCountry.Items(226).ToString
This example populates a combobox with a list of countries from a datatable returned from 'CustomSQL.GetCountryList' and then preselects UK (item 226 in the list) as the text.
What have you tried to get your answer? I assume nothing... since this is a really basic task.
See: http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.items.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]
You populate it calling theAdd
method of itsItems
property, e.g.
myComboBox.Items.Add("first item")
这篇关于填充以编程方式制作的组合框(不在设计器中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文