Dataset and Bindings

D

dave

HI All,

1) I open up a dataset (declared at the module level)
2) I get the data with the .FILL using the DataAdapter
3) I update a DataGrid RecordSource property to the DataSource
4) I update the DataBindings of a Text box to one of those fields.

Now, the data loads into the datagrid and the text box just fine.
When I move around in the datagrid, it changes the value in the text
box.

Now, how do I change the current record using code? I've tried using
the:

me.bindingcontext(dsCustomer, "dtCustomer").position

Modifing this values does not modify the control on the screen and
changing the record position on the screen does not change the
bindingcontext.position value.

Any help is appreciated.

Dave.
 
P

Patrick

Dave,
That should work (assuming you are using the .ToString()
method).

lblRecord.Text = me.bindingcontext
(dsCustomer, "dtCustomer").position.ToString(). The
position method returns an int. One of my projects uses
the very same. Good luck
 
B

Brad Allison

Dave,

This is what I use in one of my programs to advance one record:
Me.BindingContext(dataset, "TableName").Position += 1

I then use ... +-1 to go back one and so on.

Hope this helps.

Brad Allison
 
D

dave

Thanks Brad and Patrick,

I figured it out. Before, I had:

FormLoad
========
mconnCust = New SqlConnection(....)
mdaCust = New SqlDataAdapter("Select * from Customers", mconnCust)
mdaCust.Fill(mdsCust, "dtCustomer")
DataGrid1.DataSource = mdsCust.Tables("dtCustomer")
tCustomerID.DataBindings.Add("Text", mdsCust.Tables("dtCustomer"),_
"CustomerID")

Now this would populate the datagrid and the textbox. Changing the
position of the datagrid would change the value in the textbox. When
I did a:

MsgBox(Me.BindingContext(mdsCust.Tables("dtCustomer")).Position

It would always return 0, regardless of where I was on the datagrid.
Changing this value would NOT update the position in the datagrid or
the textbox.

I then added a databindings to the datagrid,

FormLoad
========
mconnCust = New SqlConnection(....)
mdaCust = New SqlDataAdapter("Select * from Customers", mconnCust)
mdaCust.Fill(mdsCust, "dtCustomer")
DataGrid1.DataSource = mdsCust.Tables("dtCustomer")
tCustomerID.DataBindings.Add("Text", mdsCust.Tables("dtCustomer"),_
"CustomerID")
DataGrid1.DataBindings.Add("", mdsCust,_
mdsCust.Tables("dtCustomer").TableName)

It now works like a charm.
 

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

Top