By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

Combo Box Binding problems

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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
Nov 21 '05 #2

P: n/a
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:
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


Nov 21 '05 #3

P: n/a
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:
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

Nov 21 '05 #4

P: n/a
Yes that's right!

Richard
On Thu, 14 Jul 2005 20:50:55 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
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.Clos eConnection)

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:
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


Nov 21 '05 #5

P: n/a
Hi,

I looked at you code again. In vs.net 2002, 2003, and 2005
there is no add method for the combobox. Where did that line come from?

Ken
------------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:o5********************************@4ax.com...
Yes that's right!

Richard
On Thu, 14 Jul 2005 20:50:55 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
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.Clos eConnection)

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:
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

Nov 21 '05 #6

P: n/a
Thank you for your help Ken. I see what you mean. I've just changed
this line to

With cboAdvertising
.DataSource = arrAdvertising
.ValueMember = "ID"
.DisplayMember = "Name"
.DataBindings.Add("SelectedValue", objDataView,
"AdvertisingMedium")
End With

But the only difference I can make is if I try to bind the combobox
before adding the Datasource, Valuemember and Displaymember
propertties, there is a blank in the combobox, and if I bind the the
combobox to the field afterwards (as shown) the form loads with the
first value in the combobox selected.

Still cannot get it to display the actual data in the field when the
form loads though!

Richard



On Fri, 15 Jul 2005 06:08:45 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

I looked at you code again. In vs.net 2002, 2003, and 2005
there is no add method for the combobox. Where did that line come from?

Ken
------------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:o5********************************@4ax.com.. .
Yes that's right!

Richard
On Thu, 14 Jul 2005 20:50:55 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
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.Clo seConnection)

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:
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


Nov 21 '05 #7

P: n/a
Hi,

You are setting the datasource, displaymember, and valuemember.
You do not need the databindings.add line.

Ken
-------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:tu********************************@4ax.com...
Thank you for your help Ken. I see what you mean. I've just changed
this line to

With cboAdvertising
.DataSource = arrAdvertising
.ValueMember = "ID"
.DisplayMember = "Name"
.DataBindings.Add("SelectedValue", objDataView,
"AdvertisingMedium")
End With

But the only difference I can make is if I try to bind the combobox
before adding the Datasource, Valuemember and Displaymember
propertties, there is a blank in the combobox, and if I bind the the
combobox to the field afterwards (as shown) the form loads with the
first value in the combobox selected.

Still cannot get it to display the actual data in the field when the
form loads though!

Richard



On Fri, 15 Jul 2005 06:08:45 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

I looked at you code again. In vs.net 2002, 2003, and 2005
there is no add method for the combobox. Where did that line come from?

Ken
------------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:o5********************************@4ax.com.. .
Yes that's right!

Richard
On Thu, 14 Jul 2005 20:50:55 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
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.Clo seConnection)

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:
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

Nov 21 '05 #8

P: n/a
Hi Ken,

Sorry if I've confused things.

The datasource of the combobox is merely the lookup table that
provides the primary key and description values for the arraylist
which then populates the displaymember and valuemember properties
combobox.

Without the databindings.add line, there is nothing to bind the
combobox to the foreign key of the form's datasource.

Richard


On Fri, 15 Jul 2005 17:31:53 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

You are setting the datasource, displaymember, and valuemember.
You do not need the databindings.add line.

Ken
-------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:tu********************************@4ax.com.. .
Thank you for your help Ken. I see what you mean. I've just changed
this line to

With cboAdvertising
.DataSource = arrAdvertising
.ValueMember = "ID"
.DisplayMember = "Name"
.DataBindings.Add("SelectedValue", objDataView,
"AdvertisingMedium")
End With

But the only difference I can make is if I try to bind the combobox
before adding the Datasource, Valuemember and Displaymember
propertties, there is a blank in the combobox, and if I bind the the
combobox to the field afterwards (as shown) the form loads with the
first value in the combobox selected.

Still cannot get it to display the actual data in the field when the
form loads though!

Richard



On Fri, 15 Jul 2005 06:08:45 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

I looked at you code again. In vs.net 2002, 2003, and 2005
there is no add method for the combobox. Where did that line come from?

Ken
------------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:o5********************************@4ax.com. ..
Yes that's right!

Richard
On Thu, 14 Jul 2005 20:50:55 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
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.Cl oseConnection)

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:

Hi,

Please post some code.

Ken
--------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:4c********************************@4ax.co m...
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


Nov 21 '05 #9

P: n/a
Sorry Ken,

My I am just trying to load the value that is already in the form's
dataset to display in the combo box when the form loads. I've taken
that line out but it does nothing.

Richard

On Fri, 15 Jul 2005 23:24:14 +0100, Richard
<xx******************@yahoo.co.uk> wrote:
Hi Ken,

Sorry if I've confused things.

The datasource of the combobox is merely the lookup table that
provides the primary key and description values for the arraylist
which then populates the displaymember and valuemember properties
combobox.

Without the databindings.add line, there is nothing to bind the
combobox to the foreign key of the form's datasource.

Richard


On Fri, 15 Jul 2005 17:31:53 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

You are setting the datasource, displaymember, and valuemember.
You do not need the databindings.add line.

Ken
-------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:tu********************************@4ax.com. ..
Thank you for your help Ken. I see what you mean. I've just changed
this line to

With cboAdvertising
.DataSource = arrAdvertising
.ValueMember = "ID"
.DisplayMember = "Name"
.DataBindings.Add("SelectedValue", objDataView,
"AdvertisingMedium")
End With

But the only difference I can make is if I try to bind the combobox
before adding the Datasource, Valuemember and Displaymember
propertties, there is a blank in the combobox, and if I bind the the
combobox to the field afterwards (as shown) the form loads with the
first value in the combobox selected.

Still cannot get it to display the actual data in the field when the
form loads though!

Richard



On Fri, 15 Jul 2005 06:08:45 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

I looked at you code again. In vs.net 2002, 2003, and 2005
there is no add method for the combobox. Where did that line come from?

Ken
------------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:o5********************************@4ax.com ...
Yes that's right!

Richard
On Thu, 14 Jul 2005 20:50:55 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:

Hi,

Are Name and ID properties in the Category class?

Ken
-------------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:d1********************************@4ax.co m...
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.C loseConnection)

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:

>Hi,
>
> Please post some code.
>
>Ken
>--------------
>"Richard" <xx******************@yahoo.co.uk> wrote in message
>news:4c********************************@4ax.c om...
>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
>


Nov 21 '05 #10

P: n/a
I've sorted this problem out now. I've got rid of the class I was
using and used a dataset/dataadapter method.

Much simpler.

Richard

On Sun, 17 Jul 2005 14:08:23 +0100, Richard
<xx******************@yahoo.co.uk> wrote:
Sorry Ken,

My I am just trying to load the value that is already in the form's
dataset to display in the combo box when the form loads. I've taken
that line out but it does nothing.

Richard

On Fri, 15 Jul 2005 23:24:14 +0100, Richard
<xx******************@yahoo.co.uk> wrote:
Hi Ken,

Sorry if I've confused things.

The datasource of the combobox is merely the lookup table that
provides the primary key and description values for the arraylist
which then populates the displaymember and valuemember properties
combobox.

Without the databindings.add line, there is nothing to bind the
combobox to the foreign key of the form's datasource.

Richard


On Fri, 15 Jul 2005 17:31:53 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

You are setting the datasource, displaymember, and valuemember.
You do not need the databindings.add line.

Ken
-------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:tu********************************@4ax.com ...
Thank you for your help Ken. I see what you mean. I've just changed
this line to

With cboAdvertising
.DataSource = arrAdvertising
.ValueMember = "ID"
.DisplayMember = "Name"
.DataBindings.Add("SelectedValue", objDataView,
"AdvertisingMedium")
End With

But the only difference I can make is if I try to bind the combobox
before adding the Datasource, Valuemember and Displaymember
propertties, there is a blank in the combobox, and if I bind the the
combobox to the field afterwards (as shown) the form loads with the
first value in the combobox selected.

Still cannot get it to display the actual data in the field when the
form loads though!

Richard



On Fri, 15 Jul 2005 06:08:45 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:

Hi,

I looked at you code again. In vs.net 2002, 2003, and 2005
there is no add method for the combobox. Where did that line come from?

Ken
------------------
"Richard" <xx******************@yahoo.co.uk> wrote in message
news:o5********************************@4ax.co m...
Yes that's right!

Richard
On Thu, 14 Jul 2005 20:50:55 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:

>Hi,
>
> Are Name and ID properties in the Category class?
>
>Ken
>-------------------
>"Richard" <xx******************@yahoo.co.uk> wrote in message
>news:d1********************************@4ax.c om...
>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. CloseConnection)
>
> 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:
>
>>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
>>
>


Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.