473,695 Members | 2,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Catego ryID) and Categories(Cate goryID).
i.e.
dsProducts.Tabl es("products") is the data of table "Products"
dsProducts.Tabl es("categories" ) is the data of table "Categories "
The relationship name of the two tables is "product_catego ry"

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

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

Private Sub form1_load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
..... ' others codes
With cboCategories
.DisplayMember = "CategoryNa me"
.ValueMember = "CategoryID "
.DataSource = Me.dsUser_Roles .Tables("catego ryies")
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.Ad d(New Binding("Text", dsProducts,
"products.Produ ctName"))

' TextBox binding: txtQuantityPerU nit<-> QuantityPerUnit field of
Products table
txtQuantityPerU nit.DataBinding s.Add(New Binding("Text", dsProducts,
"products.Quant ityPerUnit"))

' TextBox binding: txtUnitPrice <-> UnitPrice field of Products table
txtUnitPrice.Da taBindings.Add( New Binding("Text", dsProducts,
"products.UnitP rice"))
' cboCategories binding: cboCategories <-> CategoryID field of Products
table
cboCategories.D ataBindings.Add (New Binding("Text", dsProducts,
"products.Categ oryID"))

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 2626

Hello Bruce,

Try binding to the SelectedValue property instead of Text:

| cboCategories.D ataBindings.Add (New Binding("Select edValue", dsProducts,
| "products.Categ oryID"))

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: AcTwPS9cTv2vuhE RRwWfBWyk+RjYIg ==
| X-WBNR-Posting-Host: 64.229.237.74
| From: "=?Utf-8?B?QnJ1Y2U=?=" <Br***@discussi ons.microsoft.c om>
| Subject: comboBox binding question(with different DisplayMember &
ValueMemb
| Date: Sat, 1 Jan 2005 12:05:05 -0800
| Lines: 80
| Message-ID: <B6************ *************** *******@microso ft.com>
| 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.publi c.dotnet.langua ges.vb
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.1.29
| Path: cpmsftngxa10.ph x.gbl!TK2MSFTNG XA03.phx.gbl
| Xref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:251510
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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(Catego ryID) and Categories(Cate goryID).
| i.e.
| dsProducts.Tabl es("products") is the data of table "Products"
| dsProducts.Tabl es("categories" ) is the data of table "Categories "
| The relationship name of the two tables is "product_catego ry"
|
| There is a comboBox named "cboCategories" , binding to Categories table,
and
| set the DisplayMember as "CategoryNa me", ValueMember as "CategoryID ". The
| binding will be finished when the form1 is loaded.
|
| \\\\\
| '........ other codes
|
| Private Sub form1_load(ByVa l sender As System.Object, ByVal e As
| System.EventArg s) Handles MyBase.Load
| ..... ' others codes
| With cboCategories
| .DisplayMember = "CategoryNa me"
| .ValueMember = "CategoryID "
| .DataSource = Me.dsUser_Roles .Tables("catego ryies")
| 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.Ad d(New Binding("Text", dsProducts,
| "products.Produ ctName"))
|
| ' TextBox binding: txtQuantityPerU nit<-> QuantityPerUnit field of
| Products table
| txtQuantityPerU nit.DataBinding s.Add(New Binding("Text", dsProducts,
| "products.Quant ityPerUnit"))
|
| ' TextBox binding: txtUnitPrice <-> UnitPrice field of Products table
| txtUnitPrice.Da taBindings.Add( New Binding("Text", dsProducts,
| "products.UnitP rice"))
|
|
| ' cboCategories binding: cboCategories <-> CategoryID field of Products
| table
| cboCategories.D ataBindings.Add (New Binding("Text", dsProducts,
| "products.Categ oryID"))
|
| 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
6019
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 the SelectedItem. But I want to override the it. Overriding the ToString() of the class of the SelectedItem doesn't help because I can't touch the class. Maybe I have to rewrite the WndProc WM_PAINT. Whatever, I just need an idea. ... Thanks!
4
1975
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, which could be why no-one answered it!! I've now narrowed the problem down, so am starting a new, more specific, thread. Sorry it's a bit long, but it's reasonably simple stuff. I have a page where I'm showing product details, including any
2
1229
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: System.Data.DataRowView If I click on one, it navigates to the right place. Any idea how I would get the System.Data.DataRowView to show the actual values in the column? Thanks
2
2688
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". That was my code, can you help me. Thanks! Tr 'Create connection object Dim strConnNorthwind As String = "Provider=oraoledb.oracle;User Id=sigrem; " &
4
4615
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 bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have distilled the problem down to a simple form drawing data from the Northwind database for a representative...
1
7068
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 form is called MasterForm, it has a two columned comboBox called InsPVComboList. "Text.(0,0)" is my attempt to add to the where condition in the macro to isolate each entry in the combobox. I have tried Inselection.(0,0) but it did not work.
4
28226
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 create an ArrayList that contains only rows of string data and want to assign this to the DataSource but I can't figure out what to set the ValueMember or DisplayMember to. Example ArrayList myData = new ArrayList(); myData.Add("abc");
2
7134
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 are in MFC I have to remain constrained only in C#. I have tried to add checked listbox in combobox drop down list but it is showing in text format i.e. name of the control added, if I change display property of combobox with some property of...
3
2718
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 displays data 2 fields from my Error table; Error Num and Error which is a description of the error I would like it to update 2 fields in my issues table - Error Type and Problem Short. I can currently get it to update Error Type with the Error Num...
0
8631
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
8572
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
8984
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8847
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8825
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
7661
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
4340
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
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2272
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.