G
Guest
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
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