Strongly typed data - the 'current row'

  • Thread starter Thread starter Larry Lard
  • Start date Start date
L

Larry Lard

I've got a Windows Forms app talking to an Access db, and I'm
experimenting with VS2005's form data binding stuff etc.

I've got a dataset, a datagridview bound to a query (let's call it
Customers), and I have a button called Edit, which when clicked should
spawn a dialog wherein the customer associated with the current row in
the grid should be edited.

So I need to pass the 'current' Customer ID to this form. There's an
topic in the help titled "Walkthrough: Passing Data Between Forms in a
Windows Application" wherein a similar thing happens: to quote,

"Using the customers and orders tables from Northwind one form will
allow users to select a customer and a second form will display the
selected customer's orders. This walkthrough shows how to create a
method on one form that receives data from the first form."

The relevant part of the walkthrough is this:

Private Sub CustomersDataGridView_DoubleClick(ByVal sender As Object,
ByVal e As System.EventArgs) _
Handles CustomersDataGridView.DoubleClick

Dim SelectedRowView As Data.DataRowView
Dim SelectedRow As NorthwindDataSet.CustomersRow

SelectedRowView = CType(CustomersBindingSource.Current,
System.Data.DataRowView)
SelectedRow = CType(SelectedRowView.Row,
NorthwindDataSet.CustomersRow)

Dim OrdersForm As New Form2
OrdersForm.LoadOrders(SelectedRow.CustomerID)
OrdersForm.Show()
End Sub

My question is - what's with all these CTypes? I've (or rather, the IDE
has) gone to all this trouble to make a whole bundle of strongly-typed
types for my dataset, my datatables, my tableadapters, my columns, my
rows, change events etc etc (the xsd file is enormous when you look at
it in code!) - and yet just to say 'the current value of column X for
data object Y' I have to do 2 CTypes?

Surely there's a cleaner way of just saying 'the current customer ID' ?
 
Bind the CustomerId to a control on the form (hidden or otherwise) and pick
it up from that and bypass having to use the navigator objects to get it.

OrdersForm.LoadOrders(Me.CustomerIDLabel)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top