By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

A few basic questions on DataView and DataBinding (Mainly syntax)

P: n/a
1. If I create a sorted DataView object from a DataSet table, how do I
reference the sorted elements? (Say I want to output the CustomerName
for the first row in the sorted DataView to a label or textbox)

Dim view As DataView = New DataView(dsDataset.Customer)
view.Sort = "CustomerID ASC"
DataGrid1.DataSource = view

2. If after displaying the CustomerName above for the first row in the
sorted DataView, how do I then change it's value. Normally with a
DataSet I'd use:

dsDataset.Customer.Rows(intRowPos)("CustomerName") = "John Smith"

But how would it be done using the DataView. I know a DataView is read
only so obviously I'll have to pass a paramater to the Dataset code
above so it knows, that "this DataView row matches this DataSet table
row".

3.
lblCustomerID.DataBindings.Add("Text", dsDataset,
"Customer.CustomerID")
lblCustomerAddress.DataBindings.Add("Text", dsDataset,
"Customer.CustomerAddress")

cmbCustomerName.DataSource = dsDataset
cmbCustomerName.DisplayMember = "Customer.CustomerSurname"
cmbCustomerName.ValueMember = "Customer.CustomerID"

The above code populates and binds a ComboBox so that when a Surname is
selected it simply outputs the related CustomerID and CustomerAddress
to labels. How do I make it so that both CustomerSurname and the
related CustomerForename both appear in the ComboBox?
4. What's the alternative to Q3 if I don't wanna use Binding. This is
what i have so far:

Private Sub FillComboBox()
Dim intCustomerRow As Integer = 0
cmbCustomerName.Items.Clear()

Do Until intCustomerRow = dsTurbobraze.Customer.Rows.Count

cmbCustomerName.Items.Add(dsTurbobraze.Customer.Ro ws(intRowPos)_
("CustomerSurname").ToString() & ", " &
dsTurbobraze.Customer.Rows(intRowPos)_
("CustomerForename").ToString())
intCustomerRow = intCustomerRow + 1
intRowPos = intRowPos + 1
Loop
End Sub

But all this does is fill the ComboBox with the Forenames and Surnames.
I've tried loads of code in cmbCustomerName_SelectedIndexChanged but
none works.
I know these are basic Q's, but they also tend to be difficult to find
since everyone assumes everyone else knows it.

--

Aziz

Mar 30 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.