473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ComboBox data binding woes

Hi everyone,
As usual, weekend is tinkering time for students and I'm playing with
combobox databinding for the first time. Previously I have always iterated
through the records and added each item in the rows manually. Just thought
it would be nice to do it properly for a change.

Here's the bit of code I experiment with:
================================================== ==========================
========================
Private Sub Create_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
txtResDate.Text = Date.Today
Dim command1 As New OleDb.OleDbCommand("select code, location from
airport where code in (select
distinct orig from flight)", con)
Dim daOrig As New OleDb.OleDbDataAdapter(command1)
Dim dest As New DataSet
Dim orig As New DataSet
Try
con.Open()
orig.Clear()
daOrig.Fill(orig)
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

With cboOrig
.DataSource = orig.Tables(0).DefaultView
.DisplayMember = "Location"
'.ValueMember = "Code"
End With
End Sub
================================================== =========================
It seemed to only partially work. The combobox had the correct number of
items but each item was displayed as "System.Data.DataRowView", instead of
the actual value.

I also had to comment out the setting of the ValueMember property as I got
the error "Could not bind to the new display member." I'm a bit stumped as
to why this doesn't work. I've scrounged around the net for examples, etc.
but they generally point to this type of code. Did I miss something?

Any suggestions would be greatly appreciated.

Cheers,
Dany.
Nov 20 '05 #1
6 1364
Hi,

The displaymember is case sensitive. Try this instead.

With cboOrig
.DataSource = orig.Tables(0).DefaultView
.DisplayMember = "location"
.ValueMember = "code"
End With
Ken
----------------
"Dany P. Wu" <da**@no-spam.wu.net.nz> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi everyone,
As usual, weekend is tinkering time for students and I'm playing with
combobox databinding for the first time. Previously I have always iterated
through the records and added each item in the rows manually. Just thought
it would be nice to do it properly for a change.

Here's the bit of code I experiment with:
================================================== ==========================
========================
Private Sub Create_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
txtResDate.Text = Date.Today
Dim command1 As New OleDb.OleDbCommand("select code, location from
airport where code in (select
distinct orig from flight)", con)
Dim daOrig As New OleDb.OleDbDataAdapter(command1)
Dim dest As New DataSet
Dim orig As New DataSet
Try
con.Open()
orig.Clear()
daOrig.Fill(orig)
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

With cboOrig
.DataSource = orig.Tables(0).DefaultView
.DisplayMember = "Location"
'.ValueMember = "Code"
End With
End Sub
================================================== =========================
It seemed to only partially work. The combobox had the correct number of
items but each item was displayed as "System.Data.DataRowView", instead of
the actual value.

I also had to comment out the setting of the ValueMember property as I got
the error "Could not bind to the new display member." I'm a bit stumped as
to why this doesn't work. I've scrounged around the net for examples, etc.
but they generally point to this type of code. Did I miss something?

Any suggestions would be greatly appreciated.

Cheers,
Dany.

Nov 20 '05 #2
In news:ul**************@tk2msftngp13.phx.gbl,
Ken Tucker [MVP] <vb***@bellsouth.net> typed:
Hi,

The displaymember is case sensitive. Try this instead.

With cboOrig
.DataSource = orig.Tables(0).DefaultView
.DisplayMember = "location"
.ValueMember = "code"
End With


Thanks for the suggestion Ken. Unfortunately that didn't quite do the trick.

I still get the same error when I ran your suggested code - namely "Could
not bind to the new display member." at the ValueMember line.

When I commented out the setting of the ValueMember, the combobox was
populated with 5 items, which correctly corresponded to the number of rows
that should be returned. Unfortunately each item still display the same
thing, i.e. "System.Data.DataRowView".

This is really puzzling me - I really can't think of why such a simple bit
of code wouldn't work. Any other suggestions?

Cheers,
Dany.
Nov 20 '05 #3
Dany:

Just for giggles, set location as the ValueMember too (so it's set for both)
and see if it 'works'. Everythign else here looks fine and I'm wondering if
the word code isn't causing the issue. If it is, changing the alias to
somehting else should fix it but before you do that, see if it will work
with location.

Also, it appears that you have two datasets and one isn't being used. It's
a rare scenario where you need two datasets in one app but as an aside, you
may want to get rid of code you aren't using (forgive my pickyness, I've
been refactoring stuff all day and it sticks out like a sort thumb). Let me
knonw what happens with Valuemember.

Cheers,

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"Dany P. Wu" <da**@no-spam.wu.net.nz> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
In news:ul**************@tk2msftngp13.phx.gbl,
Ken Tucker [MVP] <vb***@bellsouth.net> typed:
Hi,

The displaymember is case sensitive. Try this instead.

With cboOrig
.DataSource = orig.Tables(0).DefaultView
.DisplayMember = "location"
.ValueMember = "code"
End With
Thanks for the suggestion Ken. Unfortunately that didn't quite do the

trick.
I still get the same error when I ran your suggested code - namely "Could
not bind to the new display member." at the ValueMember line.

When I commented out the setting of the ValueMember, the combobox was
populated with 5 items, which correctly corresponded to the number of rows
that should be returned. Unfortunately each item still display the same
thing, i.e. "System.Data.DataRowView".

This is really puzzling me - I really can't think of why such a simple bit
of code wouldn't work. Any other suggestions?

Cheers,
Dany.

Nov 20 '05 #4
In news:ef*************@TK2MSFTNGP10.phx.gbl,
William Ryan eMVP <do********@comcast.nospam.net> typed:
Dany:

Just for giggles, set location as the ValueMember too (so it's set
for both) and see if it 'works'. Everythign else here looks fine and
I'm wondering if the word code isn't causing the issue. If it is,
changing the alias to somehting else should fix it but before you do
that, see if it will work with location.
Thanks for the suggestion, Bill. Not much of a giggle though :o)
Unfortunately everything was the same - same errors, etc. I had to comment
out the ValueMember as it gave the same error as I posted originally.
Also, it appears that you have two datasets and one isn't being used.
It's a rare scenario where you need two datasets in one app but as an
aside, you may want to get rid of code you aren't using (forgive my
pickyness, I've been refactoring stuff all day and it sticks out like
a sort thumb). Let me knonw what happens with Valuemember.


Yup! The original code had two datasets, each one providing data for two
comboboxes. I didn't include both in the posting because it's more or less
identical to the each other.

Cheers,
Dany.
Nov 20 '05 #5
In news:ef*************@TK2MSFTNGP10.phx.gbl,
William Ryan eMVP <do********@comcast.nospam.net> typed:
Dany:

Just for giggles, set location as the ValueMember too (so it's set
for both) and see if it 'works'. Everythign else here looks fine and
I'm wondering if the word code isn't causing the issue. If it is,
changing the alias to somehting else should fix it but before you do
that, see if it will work with location.
Thanks for the suggestion, Bill. Not much of a giggle though :o)
Unfortunately everything was the same - same errors, etc. I had to comment
out the ValueMember as it gave the same error as I posted originally.
Also, it appears that you have two datasets and one isn't being used.
It's a rare scenario where you need two datasets in one app but as an
aside, you may want to get rid of code you aren't using (forgive my
pickyness, I've been refactoring stuff all day and it sticks out like
a sort thumb). Let me knonw what happens with Valuemember.


Yup! The original code had two datasets, each one providing data for two
comboboxes. I didn't include both in the posting because it's more or less
identical to the each other.

Cheers,
Dany.
Nov 20 '05 #6

try puting
..ValueMember()
before
..DataSource =

and remember
..DisplayMember is case sensitive

--
t14385
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message720616.html

May 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bruce | last post by:
Hi, there, I meet a problem about comboBox binding. -------------------- Database: Northwind Tables: 1) Products 2) Categories I create a form (named "form1") to edit the record from...
2
by: SKarnis | last post by:
We are trying to rebuild a current Access 2002 (XP) mdb program to VB.NET with a SQL database - we are having problems with a suitable combobox. There are many threads discussing multiple column...
3
by: amber | last post by:
Hello, I have 6 comboboxes, that I thought I could bind to the same datasource, and have them display different 'selectedvalue's', but apparently I can't... My code is as follows: dim drv as...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
0
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number...
19
by: active | last post by:
I'm using a ComboBox to display objects of a class I've defined, say CQQ. Works great except somehow I occasionally set an Item to a String object instead of an object of type CQQ. It looks...
3
by: Przemek M. Zawada | last post by:
Dear Group, I'm developing sample window form, using DataGridView control, which is filled with data through BindingSource, which is based on type of object, as follow: public sampleClass {...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.