473,395 Members | 2,713 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,395 software developers and data experts.

comboBox binding question(with different DisplayMember & ValueMemb

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.

dsProducts is a DataSet object to storage the data from Products and
Categories tables, and the Foreign Reference relationship between
Products(CategoryID) and Categories(CategoryID).
i.e.
dsProducts.Tables("products") is the data of table "Products"
dsProducts.Tables("categories") is the data of table "Categories"
The relationship name of the two tables is "product_category"

There is a comboBox named "cboCategories", binding to Categories table, and
set the DisplayMember as "CategoryName", ValueMember as "CategoryID". The
binding will be finished when the form1 is loaded.

\\\\\
'........ other codes

Private Sub form1_load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
..... ' others codes
With cboCategories
.DisplayMember = "CategoryName"
.ValueMember = "CategoryID"
.DataSource = Me.dsUser_Roles.Tables("categoryies")
End With
..... ' others codes
Set_binding()
..... ' others codes

End sub

'........ other codes

Private Sub Set_binding()
' TextBox binding: txtProductName <-> ProductName field of Products table
txtProductName.DataBindings.Add(New Binding("Text", dsProducts,
"products.ProductName"))

' TextBox binding: txtQuantityPerUnit<-> QuantityPerUnit field of
Products table
txtQuantityPerUnit.DataBindings.Add(New Binding("Text", dsProducts,
"products.QuantityPerUnit"))

' TextBox binding: txtUnitPrice <-> UnitPrice field of Products table
txtUnitPrice.DataBindings.Add(New Binding("Text", dsProducts,
"products.UnitPrice"))
' cboCategories binding: cboCategories <-> CategoryID field of Products
table
cboCategories.DataBindings.Add(New Binding("Text", dsProducts,
"products.CategoryID"))

End Sub

'........ other codes

\\\\\\\\\

When I navigate the data in products, a new item with the CategoryID value
from Products table is added, not the CategoryName. I want to show the
related CategoryName other than CategoryID when navigating the data in
Products table.

How to solve the problem?

Thanks a lot.

Bruce
Nov 21 '05 #1
1 2603

Hello Bruce,

Try binding to the SelectedValue property instead of Text:

| cboCategories.DataBindings.Add(New Binding("SelectedValue", dsProducts,
| "products.CategoryID"))

hope that helps

Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.

--------------------
| Thread-Topic: comboBox binding question(with different DisplayMember &
ValueMemb
| thread-index: AcTwPS9cTv2vuhERRwWfBWyk+RjYIg==
| X-WBNR-Posting-Host: 64.229.237.74
| From: "=?Utf-8?B?QnJ1Y2U=?=" <Br***@discussions.microsoft.com>
| Subject: comboBox binding question(with different DisplayMember &
ValueMemb
| Date: Sat, 1 Jan 2005 12:05:05 -0800
| Lines: 80
| Message-ID: <B6**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.vb:251510
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| 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.
|
| dsProducts is a DataSet object to storage the data from Products and
| Categories tables, and the Foreign Reference relationship between
| Products(CategoryID) and Categories(CategoryID).
| i.e.
| dsProducts.Tables("products") is the data of table "Products"
| dsProducts.Tables("categories") is the data of table "Categories"
| The relationship name of the two tables is "product_category"
|
| There is a comboBox named "cboCategories", binding to Categories table,
and
| set the DisplayMember as "CategoryName", ValueMember as "CategoryID". The
| binding will be finished when the form1 is loaded.
|
| \\\\\
| '........ other codes
|
| Private Sub form1_load(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles MyBase.Load
| ..... ' others codes
| With cboCategories
| .DisplayMember = "CategoryName"
| .ValueMember = "CategoryID"
| .DataSource = Me.dsUser_Roles.Tables("categoryies")
| End With
| ..... ' others codes
| Set_binding()
| ..... ' others codes
|
| End sub
|
| '........ other codes
|
| Private Sub Set_binding()
| ' TextBox binding: txtProductName <-> ProductName field of Products
table
| txtProductName.DataBindings.Add(New Binding("Text", dsProducts,
| "products.ProductName"))
|
| ' TextBox binding: txtQuantityPerUnit<-> QuantityPerUnit field of
| Products table
| txtQuantityPerUnit.DataBindings.Add(New Binding("Text", dsProducts,
| "products.QuantityPerUnit"))
|
| ' TextBox binding: txtUnitPrice <-> UnitPrice field of Products table
| txtUnitPrice.DataBindings.Add(New Binding("Text", dsProducts,
| "products.UnitPrice"))
|
|
| ' cboCategories binding: cboCategories <-> CategoryID field of Products
| table
| cboCategories.DataBindings.Add(New Binding("Text", dsProducts,
| "products.CategoryID"))
|
| End Sub
|
| '........ other codes
|
| \\\\\\\\\
|
| When I navigate the data in products, a new item with the CategoryID
value
| from Products table is added, not the CategoryName. I want to show the
| related CategoryName other than CategoryID when navigating the data in
| Products table.
|
| How to solve the problem?
|
| Thanks a lot.
|
| Bruce
|
|
|

Nov 21 '05 #2

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

Similar topics

3
by: | last post by:
Hello, I try to format the text of a combobox with DropDownStyle "DropDown". I just mean the text which is displayed when the combobox isn't touched. Usually it displays the ToString() method of...
4
by: Alan Silver | last post by:
Hello, I'm trying to use an ArrayList to do data binding, but am getting an error I don't understand. I posted this in another thread, but that was all confused with various other problems,...
2
by: ken | last post by:
I would like to fill a combobox with the values of one column of the dataview I am using. When I set it up the way I expect it would be, I get every row in the combobox says: ...
2
by: Antoine | last post by:
Hi I try to fill a combobox with a dataset. I see the data in the dataset, but when i try to bind this dataset with a combobox. The list is fill only whith this message "System.Data.DataRowView". ...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
1
by: mshenoud | last post by:
I have a comboBox with two columns. I would like to isolate each column so as to compare it to an entry in a table so as to be able to load a yet another form. how can I do that? Details: The...
4
by: polaris431 | last post by:
All the examples I've seen showing how to populate a combobox using the DataSource property and an ArrayList show the ArrayList object containing objects with at least two properties. I want to...
2
by: saurabhnsit2002 | last post by:
Can anyone help me about how to create combo box with its items as checked boxes or radio buttons. This has to be done in C#. I have seen something similar to this named custom combo boxes but they...
3
by: linwork | last post by:
Hi, I have a form that updates an issue log. Among the other fields on it, it contains a combobox with 2 columns that I would like to update 2 separate fields in my database. ComboErrorDesc...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
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.