Groups | Blog | Home
all groups > vb.net data > february 2004 >

vb.net data : Data Binding query


Steve
2/17/2004 12:08:53 PM
Hi all

I have just started a new project that includes Data Binding. I have bound
the textboxes on my form to a table in my DataSet. My questions are:

1. In the table that I am binding the controls to, there is an ID field.
This field relates to another table (also in the DataSet) which contains the
description of the ID. I can bind the ID field to my ComboBox, but I want to
bind it to the description field in the other table. I first used a relation
to establish a link to the other table and then bound the Combo, this worked
as it displayed the Description rather than the ID field, but if I selected
another description from the list, all the other bound controls changed
thier position to the record that relates to that Description. Basically,
what I am after is a way to display the description rather than the ID, and
have the ID updated if they change the Description so I can persist the
changes made in the DataSet back to the database.

2. I have used a Relation to get ChildRows from the related table. How do I
populate a ListBox with the values from this Array that is returned by the
method call? I am using the following code:
-----------------------------------
Dim myRow As DataRow
'// Get the row in the User table that relates to the current User
Dim oRow As DataRow =
m_oDataSet.Tables("SecUser").Rows(Me.BindingContext(m_oDataSet,
"SecUser").Position)
'// Use the relation from User to SecurityUser to get an array of all
the Security Groups the User is in
Dim myRowsArray() As DataRow = oRow.GetChildRows(m_oSecGroupRelation)
oList.DataSource = myRowsArray
'// Display all the Security Groups this User has
oList.DataMember = "SecUserGroup.GroupID"
-----------------------------------
So I have defined a relation, called the GetChildRows and have binded the ID
field (for now, will want to change later) in that table to the ListBox, but
in the ListBox all it says is System.Data.DataRow, not the ID of the entry.
I have looked at the myRowsArray() in the Locals window, and it has an entry
under ItemArray and one of the fields is the ID. So, how do I bind a ListBox
to the DataRow array after a GetChildRows call?

Thanks for any help

Kind Regards,
Steve.


Sunder NO[at]SPAM Online.microsoft.com
2/20/2004 9:46:15 PM

Steve
For Scenario 1 I think you want to make a Lookup type Combo box ,
Please See this Article for that
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskcreatinglookuptableforlistboxorcomboboxcontrol.asp

Scenario 2
I supect the Error May be i this Line
oList.DataMember = "SecUserGroup.GroupID"

I tried with with Customers , Orders in Northwind Database with the
Following Code and It worked
Dim rows() As DataRow =
Dataset11.Customers.Rows(3).GetChildRows("CustomersOrders")
ListBox1.DataSource = rows
ListBox1.DisplayMember = "OrderID"

Try Removing SecUserGroup and See

Hope this Helps

Thanks
Sunder
vb.net

--------------------
[quoted text, click to view]
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP12.phx.gbl
[quoted text, click to view]
AddThis Social Bookmark Button