组合框绑定问题 [英] Combo Box Binding problems

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

问题描述

我创建了一个设置数据视图的表单。表单使用货币管理器一次查看一个

记录。这很好用。所有我的

文本框都绑定了。


但是我有一个组合框可以从另一个获取其查找值

(广告)表(AdvertisingID,广告)。这可以工作

..然而,当它加载形式

时它不能正常工作,组合框应该绑定到AdvertisingID字段并且

显示相应的数据。


当表单加载组合框时,只显示一个空白。如果我

选择组合框,查找表中的所有值都在那里。

但是为什么在表单加载时它不显示值。


请帮忙。这已经让我疯了三天了。

只是无法弄清楚问题是什么。


我会发布我的代码: -


创建数据视图和货币管理器: -


Richard

I have created a form which sets up a dataview. The form views one
record at a time using a currencymanager. This works fine. All my
text boxes bind.

However I have a combo box which gets its lookup values from another
(Advertising) table (AdvertisingID, Advertising). This works
.. However, where it doesn''t work as well is when the form
loads, the combo boxes should bind to the AdvertisingID field and
display the respective data.

When the form loads the combo box only displays a blank. If I
select the combo box all the values from the lookup table are there.
But why doesn''t it display the value when the form loads.

Please help. This has been driving me nuts for three days already and
just cannot figure out what the problem is.

I''ll post my code:-

Creating the dataview and currency manager:-


Richard

推荐答案

您好,


请发一些代码。


Ken

--------------

" Richard" < XX ****************** @ yahoo.co.uk>在消息中写道

news:4c ******************************** @ 4ax.com ...

我创建了一个设置数据视图的表单。表单使用货币管理器一次查看一个

记录。这很好用。所有我的

文本框都绑定了。


但是我有一个组合框可以从另一个获取其查找值

(广告)表(AdvertisingID,广告)。这可以工作

..然而,当它加载形式

时它不能正常工作,组合框应该绑定到AdvertisingID字段并且

显示相应的数据。


当表单加载组合框时,只显示一个空白。如果我

选择组合框,查找表中的所有值都在那里。

但是为什么在表单加载时它不显示值。


请帮忙。这已经让我疯了三天了。

只是无法弄清楚问题是什么。


我会发布我的代码: -


创建数据视图和货币管理器: -


Richard
Hi,

Please post some code.

Ken
--------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:4c********************************@4ax.com...
I have created a form which sets up a dataview. The form views one
record at a time using a currencymanager. This works fine. All my
text boxes bind.

However I have a combo box which gets its lookup values from another
(Advertising) table (AdvertisingID, Advertising). This works
.. However, where it doesn''t work as well is when the form
loads, the combo boxes should bind to the AdvertisingID field and
display the respective data.

When the form loads the combo box only displays a blank. If I
select the combo box all the values from the lookup table are there.
But why doesn''t it display the value when the form loads.

Please help. This has been driving me nuts for three days already and
just cannot figure out what the problem is.

I''ll post my code:-

Creating the dataview and currency manager:-


Richard


objDataSet = New DataSet

objDataAdapter.Fill(objDataSet," Sellers")

objDataView = New DataView(objDataSet.Tables(" Sellers"))

objCurrencyManager = CType(Me.BindingContext(objDataView),

CurrencyManager)

创建绑定。这在加载表单时被调用。我已经剥夺了文本框等的绑定。


Dim strAdvertising As String =" SELECT AdvertID,Advertising" &安培; _

" FROM AdvertisingMedium"

cboAdvertising.DataBindings.Clear()


cnnOTwo =新的SqlConnection( strConnection)

cmdAdvertising =新的SqlCommand(strAdvertising,cnnOTwo)

Dim arrAdvertising As New ArrayList


试试

cnnOTwo.Open()

drSQL =

cmdAdvertising.ExecuteReader(CommandBehavior.Close Connection)


而drSQL。阅读

arrAdvertising.Add(新类别(drSQL.GetByte(0),

drSQL.GetString(1)))

结束时


drSQL.Close()


cnnOTwo.Close()


Catch exsql As SqlException

MsgBox(exsql.ToString,MsgBoxStyle.Critical,Me.Text)

结束尝试


使用cboAdvertising

.DataSource = arrAdvertising

.ValueMember =" ID"

.DisplayMember =" Name"

.Add(" SelectedValue",objDataView," Advertisi ngMedium)

结束

一切正常。我试图理解的唯一一点就是为什么

组合框没有显示它b / b $(或应该)绑定的基础字段的值。


On Thu,2005年7月14日18:12:53 -0400,Ken Tucker [MVP]

< vb *** @ bellsouth.net>写道:
objDataSet = New DataSet
objDataAdapter.Fill(objDataSet, "Sellers")
objDataView = New DataView(objDataSet.Tables("Sellers"))
objCurrencyManager = CType(Me.BindingContext(objDataView),
CurrencyManager)
Creating the bindings. This gets called on loading the form. I''ve
stripped the bindings of text boxes etc.

Dim strAdvertising As String = "SELECT AdvertID, Advertising " & _
"FROM AdvertisingMedium"

cboAdvertising.DataBindings.Clear()

cnnOTwo = New SqlConnection(strConnection)
cmdAdvertising = New SqlCommand(strAdvertising, cnnOTwo)
Dim arrAdvertising As New ArrayList

Try
cnnOTwo.Open()
drSQL =
cmdAdvertising.ExecuteReader(CommandBehavior.Close Connection)

While drSQL.Read
arrAdvertising.Add(New Category(drSQL.GetByte(0),
drSQL.GetString(1)))
End While

drSQL.Close()

cnnOTwo.Close()

Catch exsql As SqlException
MsgBox(exsql.ToString, MsgBoxStyle.Critical, Me.Text)
End Try

With cboAdvertising
.DataSource = arrAdvertising
.ValueMember = "ID"
.DisplayMember = "Name"
.Add("SelectedValue", objDataView, "AdvertisingMedium")
End With
It all works fine. The only bit I''m trying to understand is why the
combo box does not display the value of the underlying field that it
is (or should be) bound to.

On Thu, 14 Jul 2005 18:12:53 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:


请发一些代码。

Ken
-------- ------
理查德 < XX ****************** @ yahoo.co.uk>在消息中写道
新闻:4c ******************************** @ 4ax.com .. <我创建了一个设置数据视图的表单。表单使用货币管理器一次查看一条记录。这很好用。我的所有
文本框都绑定了。

但是我有一个组合框,它从另一个
(广告)表(AdvertisingID,广告)获取其查找值。这工作
。但是,当表单加载时,它不能正常工作,组合框应绑定到AdvertisingID字段并显示相应的数据。

表单加载组合框只显示一个空白。如果我选择组合框,查找表中的所有值都在那里。
但是为什么在表单加载时它没有显示值。

请帮忙。这已经让我疯了三天了。
只是无法弄清问题是什么。

我会发布我的代码: -

创建数据视图和货币经理: -


理查德
Hi,

Please post some code.

Ken
--------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:4c********************************@4ax.com.. .
I have created a form which sets up a dataview. The form views one
record at a time using a currencymanager. This works fine. All my
text boxes bind.

However I have a combo box which gets its lookup values from another
(Advertising) table (AdvertisingID, Advertising). This works
. However, where it doesn''t work as well is when the form
loads, the combo boxes should bind to the AdvertisingID field and
display the respective data.

When the form loads the combo box only displays a blank. If I
select the combo box all the values from the lookup table are there.
But why doesn''t it display the value when the form loads.

Please help. This has been driving me nuts for three days already and
just cannot figure out what the problem is.

I''ll post my code:-

Creating the dataview and currency manager:-


Richard









类别类中的名称和ID属性是什么?


Ken

------------ -------

" Richard" < XX ****************** @ yahoo.co.uk>在消息中写道

news:d1 ******************************** @ 4ax.com ...

objDataSet =新数据集

objDataAdapter.Fill(objDataSet," Sellers")

objDataView =新DataView(objDataSet.Tables) (卖方))

objCurrencyManager = CType(Me.BindingContext(objDataView),

CurrencyManager)

创建绑定。这在加载表单时被调用。我已经剥夺了文本框等的绑定。


Dim strAdvertising As String =" SELECT AdvertID,Advertising" &安培; _

" FROM AdvertisingMedium"

cboAdvertising.DataBindings.Clear()


cnnOTwo =新的SqlConnection( strConnection)

cmdAdvertising =新的SqlCommand(strAdvertising,cnnOTwo)

Dim arrAdvertising As New ArrayList


试试

cnnOTwo.Open()

drSQL =

cmdAdvertising.ExecuteReader(CommandBehavior.Close Connection)


而drSQL。阅读

arrAdvertising.Add(新类别(drSQL.GetByte(0),

drSQL.GetString(1)))

结束时


drSQL.Close()


cnnOTwo.Close()


Catch exsql As SqlException

MsgBox(exsql.ToString,MsgBoxStyle.Critical,Me.Text)

结束尝试


使用cboAdvertising

.DataSource = arrAdvertising

.ValueMember =" ID"

.DisplayMember =" Name"

.Add(" SelectedValue",objDataView," Advertisi ngMedium)

结束

一切正常。我试图理解的唯一一点就是为什么

组合框没有显示它b / b $(或应该)绑定的基础字段的值。


On Thu,2005年7月14日18:12:53 -0400,Ken Tucker [MVP]

< vb *** @ bellsouth.net>写道:
Hi,

Are Name and ID properties in the Category class?

Ken
-------------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:d1********************************@4ax.com...
objDataSet = New DataSet
objDataAdapter.Fill(objDataSet, "Sellers")
objDataView = New DataView(objDataSet.Tables("Sellers"))
objCurrencyManager = CType(Me.BindingContext(objDataView),
CurrencyManager)
Creating the bindings. This gets called on loading the form. I''ve
stripped the bindings of text boxes etc.

Dim strAdvertising As String = "SELECT AdvertID, Advertising " & _
"FROM AdvertisingMedium"

cboAdvertising.DataBindings.Clear()

cnnOTwo = New SqlConnection(strConnection)
cmdAdvertising = New SqlCommand(strAdvertising, cnnOTwo)
Dim arrAdvertising As New ArrayList

Try
cnnOTwo.Open()
drSQL =
cmdAdvertising.ExecuteReader(CommandBehavior.Close Connection)

While drSQL.Read
arrAdvertising.Add(New Category(drSQL.GetByte(0),
drSQL.GetString(1)))
End While

drSQL.Close()

cnnOTwo.Close()

Catch exsql As SqlException
MsgBox(exsql.ToString, MsgBoxStyle.Critical, Me.Text)
End Try

With cboAdvertising
.DataSource = arrAdvertising
.ValueMember = "ID"
.DisplayMember = "Name"
.Add("SelectedValue", objDataView, "AdvertisingMedium")
End With
It all works fine. The only bit I''m trying to understand is why the
combo box does not display the value of the underlying field that it
is (or should be) bound to.

On Thu, 14 Jul 2005 18:12:53 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:


请发一些代码。

Ken
-------- ------
理查德 < XX ****************** @ yahoo.co.uk>在消息中写道
新闻:4c ******************************** @ 4ax.com .. <我创建了一个设置数据视图的表单。表单使用货币管理器一次查看一条记录。这很好用。我的所有
文本框都绑定了。

但是我有一个组合框,它从另一个
(广告)表(AdvertisingID,广告)获取其查找值。这工作
。但是,当表单加载时,它不能正常工作,组合框应绑定到AdvertisingID字段并显示相应的数据。

表单加载组合框只显示一个空白。如果我选择组合框,查找表中的所有值都在那里。
但是为什么在表单加载时它没有显示值。

请帮忙。这已经让我疯了三天了。
只是无法弄清问题是什么。

我会发布我的代码: -

创建数据视图和货币经理: -

理查德
Hi,

Please post some code.

Ken
--------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:4c********************************@4ax.com.. .
I have created a form which sets up a dataview. The form views one
record at a time using a currencymanager. This works fine. All my
text boxes bind.

However I have a combo box which gets its lookup values from another
(Advertising) table (AdvertisingID, Advertising). This works
. However, where it doesn''t work as well is when the form
loads, the combo boxes should bind to the AdvertisingID field and
display the respective data.

When the form loads the combo box only displays a blank. If I
select the combo box all the values from the lookup table are there.
But why doesn''t it display the value when the form loads.

Please help. This has been driving me nuts for three days already and
just cannot figure out what the problem is.

I''ll post my code:-

Creating the dataview and currency manager:-


Richard



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

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