组合框数据绑定相关问题 [英] Combobox Databinding Related Problem

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

问题描述

这是问题所在:

我正在使用Visual Studio 2010,并且将SQL Server 2005作为数据库,已经将组合框与数据集中的表列绑定了.

Here is the problem:

I am using Visual Studio 2010 and I have SQL Server 2005 as database, I have binded the combobox with a table column from the Dataset.

 Dim a As New SqlDataAdapter("Select * from TotTab", My.Settings.Equation1ConnectionString)
            Dim ds As New DataSet
            a.Fill(ds, "tot")
With NameCand
    .DataSource = ds.Tables("tot")
    .DisplayMember = "Name"
End With


NameCand是一个绑定到TotTabName列的组合框.

主要问题是绑定列"Name"的第一条记录后在组合框上自动可见,我需要组合框的可见文本为空,并使用数据库列"Name"只是为了建议数据库中已经存在的名称. br/>
可能是问题很小,但我无法弄清楚哪里出了问题.

如果还有其他方法可以实现上述目标,请提出建议.

提前谢谢您.

我想我没有把我的问题弄清楚
我有一个组合框,其中包含Name列的所有记录,并且在运行项目时可以看到该列的第一条记录,我希望默认文本为空..
可以通过绑定来完成,还是必须删除绑定才能完成上述任务.


NameCand is a combobox which is binded to Name column of TotTab.

The main problem is after binding the first record of column "Name" is automatically visible on the combobox, I need the combobox visible text to be empty and use the database Column "Name" just for suggesting the names that are already in database.

May be the problem is small but I am not able to figure out where I am wrong.

If there is any other way of achieving the above goal so please suggest.

Thank You in advance.

I guess I didn''t made my question Clear
I have a combobox which has all the records of Name column and the 1st record of this column is visible when i run the project,I want the default text to be empty..
Can it be done with binding or I have to remove binding to achieve the above task.

推荐答案

尝试将DropDownList的SelectedIndex属性设置为 -1 SelectedValue.我不确定这一点,但我认为应该这样做.

-Eduard
Try setting the SelectedIndex property of DropDownList to -1 or the SelectedValue. I am not sure of this one but I think that should do it.

-Eduard


私有子BindComboBox()
ComboBox1.DataSource = DataSet1.Tables(供应商")
ComboBox1.DisplayMember =产品名称"
结束Sub
Private Sub BindComboBox()
ComboBox1.DataSource = DataSet1.Tables("Suppliers")
ComboBox1.DisplayMember = "ProductName"
End Sub


这篇关于组合框数据绑定相关问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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