473,769 Members | 5,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
txtResDate.Text = Date.Today
Dim command1 As New OleDb.OleDbComm and("select code, location from
airport where code in (select
distinct orig from flight)", con)
Dim daOrig As New OleDb.OleDbData Adapter(command 1)
Dim dest As New DataSet
Dim orig As New DataSet
Try
con.Open()
orig.Clear()
daOrig.Fill(ori g)
con.Close()
Catch ex As Exception
MessageBox.Show (ex.Message, "error", MessageBoxButto ns.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.Da taRowView", 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 1386
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******** ********@TK2MSF TNGP12.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(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
txtResDate.Text = Date.Today
Dim command1 As New OleDb.OleDbComm and("select code, location from
airport where code in (select
distinct orig from flight)", con)
Dim daOrig As New OleDb.OleDbData Adapter(command 1)
Dim dest As New DataSet
Dim orig As New DataSet
Try
con.Open()
orig.Clear()
daOrig.Fill(ori g)
con.Close()
Catch ex As Exception
MessageBox.Show (ex.Message, "error", MessageBoxButto ns.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.Da taRowView", 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******** ******@tk2msftn gp13.phx.gbl,
Ken Tucker [MVP] <vb***@bellsout h.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.Da taRowView".

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******** ******@TK2MSFTN GP11.phx.gbl...
In news:ul******** ******@tk2msftn gp13.phx.gbl,
Ken Tucker [MVP] <vb***@bellsout h.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.Da taRowView".

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******** *****@TK2MSFTNG P10.phx.gbl,
William Ryan eMVP <do********@com cast.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******** *****@TK2MSFTNG P10.phx.gbl,
William Ryan eMVP <do********@com cast.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
2632
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 Products table.
2
1791
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 comboboxes in .NET. We are having success with the multiple columns similar to the combobox from Access 2002 (XP). Our biggest problem is speed. In a form in Access 2002, our combobox is able to load data in a table in separate Access database...
3
4587
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 datarowview = me.listbox1.selecteditem dim dtbDL as datatable = _dataset1.Tables(0) dim dtvDL as new dataview(dtbDL) dtvDL.RowFilter = "STR_ONE" = 'Matching Text'"
6
2883
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 and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the data table. The lookup
2
8672
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 list of values from a table, and as the user selects values, a datagrid displays related records from another table because it is bound via FK relationship. My table: /****** Object: Table . Script Date: 06/19/2006
0
2018
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 of different screens down to a minimum, I'm trying to use the same Windows Forms for both browsing and for updating. This works fine for TextBoxes, but I'm running into problems with my DropDownLists (ComboBoxes).
19
2209
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 like Text replaces an item or something like that. This results in a runtime error at which time I learn that the item that should be CQQ is a String.
3
14373
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 { public int itemNumber; public string itemName;
3
7522
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 on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a datetimepicker ("Value") for it's "DateTime" property. The DateTimePicker.Visible value is set to...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.