1
我在我的SQL数据库中有一个名为“Shoppings”的表。这个有一个名为qtPisos的专栏,它描述了购物中心有多少层。在我的程序中,我想根据这个整数的数量创建一个组合框,所以用户可以选择购物中心的层次,然后它将列出该特定层次的商店。将整数转换为组合框中的数字列表 - C#
任何想法我该怎么做?
这是我的代码。
public partial class Shoppings : Form
{
private DataViewManager dsView;
private DataSet ds;
public Shoppings()
{
InitializeComponent();
}
private void Shoppings_Load(object sender, EventArgs e)
{
Login logForm = new Login();
logForm = logForm.getLoginForm();
ds = new DataSet("DsShoppings");
// Fill the Dataset with Shoppings, map Default Tablename "Table" to "Shoppings".
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Shoppings", logForm.sqlConnection);
sda.TableMappings.Add("Table", "Shoppings");
sda.Fill(this.ds);
// The DataViewManager returned by the DefaultViewManager property
// allows to create custom settings for each DataTable in the DataSet.
this.dsView = ds.DefaultViewManager;
// Combobox Databinding
ComboShopping.DataSource = this.dsView;
ComboShopping.DisplayMember = "Shoppings.nomeShopping";
ComboShopping.ValueMember = "Shoppings.idShopping";
// Text Columns DataBinding
txtTotalLojas.DataBindings.Add("Text", dsView, "Shoppings.totalLojas");
//int qtPisos = Convert.ToInt32(ds.Tables["Shoppings"].Rows[0]["qtPisos"]);
ComboPisos.DataSource = this.dsView;
谢谢你的回答!我做了一个循环的c-ish来填充下拉列表。我的问题是使其成为动态。我如何从组合框中检索当前值?在这种情况下,我需要ComboShopping.DisplayMember或ComboShopping.ValueMember。当我直接调用出现在db(p.e:table.column)中的位置时。 – Kornel 2011-05-16 17:15:00