Binding a dataset to textbox controls to update the dataset.

Hi,
I am currently looking for away to manage updating data using a dataset and textboxes on a windows form.
Scenario:
1. I'm retrieving data from a database and populating a dataset with the results (about 10 rows of data in 1 table).
2. I am then binding the dataset to a datsgridView on the form. (All is good)
3. I have a few textboxes on the form and i bind a row to the text boxes. (ill include the code below)
4. As i click on the datagridview row the contents of that row will be displyed i the textboxes. (All is good). Everyclick of the row displays new data (i am using a BindingManagerBase here to iterate through the bindings)

What i would like to happen next:
Edit one of the textboxes and when the user leaves the textbox that the changes will get saved in the dataset and reflected in the datviewGrid.
The dataset is then passed to a function to update or create a new record (Note this is NOT being done through an SQLDataAdapter)

My take on this is that i've bound the textboxes to the grid, so would this be a one way binding ds -> textbox. Do i need a binding from textbox -> ds or is this handled in the binding.

I've been mssing with bindingsources as well.

Any help would be greatly apprciated.

Cheers
Steven


Dim manager As BindingManagerBase
Dim ds a new Dataset
 
Private Sub frm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
ds = Service.GetDetails(ID) 
DataGridView1.DataSource = dsTables(0)
 
BindDetails()
 
End Sub
 
Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
        Dim RowID As Integer
        Try
            RowID = DataGridView1.CurrentRow.Index
            manager.Position = RowID
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
 
 Private Sub Textbox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Textbox1.Leave
 
        ds.AcceptChanges()
 
    End Sub
Private Sub BindDetails()
        Dim field1 As New Binding("Text", ds, "TableName.Field1")
        Dim field2 As New Binding("Text", ds, "TableName.Field2")
        manager = Me.BindingContext(ds, "TableName")
        Textbox1.DataBindings.Add(field1 )
        Textbox2.DataBindings.Add(field2 )
    End Sub

Open in new window

LVL 1
gazzacroweAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jake072Commented:
What are you having problems with?  What is not working?

Your databindings  appear ok, however, I'm not sure what's going on with your DataSet, particularly, what is this doing:

ds = Service.GetDetails(ID)

Let me know,

Jake
0
gazzacroweAuthor Commented:
Hi Jake.
Thanks for replying.
I'm populating the ds from a Stored procedure call to a database.

I can get the bindings to work fine, but i would also like to be able edit a textbox (that is bound to the dataset) and have the dataset reflect the change i make and then the dataviewgrid that has the dataset as a datasource to refresh and show the change i just made.

ds = Service.GetDetails(ID) is just populating a dataset (not important)

My problem seems to be when i call ds.acceptchanges()
I've changed a textbox value which is bound to the dataset, and then i would like the dataaset to update, but when i call dataset.haschanges()  it reurns false.

Hope this helps
0
jake072Commented:
Ok, if you've databound your controls properly, the changes should occur in the datagridview, you should not need to refresh anything.

As for calling AcceptChanges, then you're telling the Dataset that you accept the changes, and thus, there is nothing to update, so do your update first.

Jake
0
gazzacroweAuthor Commented:
Hi, Sorry for not replying sooner.
I have sorted it out. I now use a BindingSource

Dim MyBinding as new BindingSource
Dim ds as new dataset

ds = Object.GetItems
MyBinding.datasource = ds.tables(0)
DatagridView.datasource = MyBinding

This does exactly what i require.

regards, and thanks for the replys

Steven

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.