Databinding datagridview values to a textbox

.NET Programming Question

Hi Experts!  I need help databinding values from a datagridview to textboxes that the user could make changes and update. The datagridview1 is readonly. I orginally put this code in the datagridview1_RowEnter:
Me.txtEmployee.Text = .Cells("User_ID").Value
Me.txtCreateDate.Text = .Cells("Create_Date").Value
Me.txtSubmitDate.Text = .Cells("Submit_Date").Value

but I am pretty sure that will not allow me to update the dataset for the datagridview. Any Ideas?

Default Text

Verified Answer?

The member who asked this question verified this comment provided the solution that solved their problem.

by:Posted on 2008-04-02 at 12:27:03ID: 21266494

Absolutely!  You're changing the DataSource right there, and that's why they are not in synch!  
(Not to mention that if there is 0 rows, there won't be any data.)

What you need to do is:

Private Sub cbEmployee_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbEmployee.SelectedIndexChanged

        Dim bs As BindingSource = Me.DataGridView1.DataSource    'get the bindingsource

        ' Assigns User_ID to the userid
        userid = DirectCast(cbEmployee.SelectedItem, DataRowView).Item("User_ID")
            userid = DirectCast(cbEmployee.SelectedItem, DataRowView).Item("User_ID")
            'loads the datagridview with the information from the Master Report by Userid selected

            dsv = LoadMaster(userid)
            bs.DataSource = dsv    'reset the datasource

            'DataGridView1.DataSource = dsv.Tables(0).DefaultView  <should not be needed

        Catch ex As Exception

        End Try
    End Sub

That should work, let me know if you have any problems.

This content is available to Experts Exchange members

See the answer now
with your Free 30 Day Trial

Get unlimited access to solutions & experts

  • 4,169,477 solved questions
  • 3,805 articles & videos
  • 15,413 tech experts

Get Access Now

Need a customized answer?
Ask your question for one-on-one assistance. We will email you when an expert has commented on your question.

We will never share this with anyone. Privacy Policy Terms of Use

Select topics

You may select up to five topics.


Related Articles

Related Questions

Experts Exchange powers the growth and success
of technology professionals worldwide.

  • Solve

    Experts Exchange is the tech professional’s trusted, on-demand resource for solving difficult problems, making informed decisions, and delivering excellent solutions.

  • Learn

    With unparalleled access to technical experts, verified real-world solutions, and diverse educational content, Experts Exchange enables personalized development of technology skills.

  • Network

    Experts Exchange gives you the professional exposure and valued relationships key to building the career you want.

Join the Network Today

See Plans and Pricing