Databinding datagridview values to a textbox

    Question by:
    On

    Topics:

    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?

    Good Question?
    0
     

    ?

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

    Accepted Solution 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")
            Try
                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.

    Top Expert Contributor

    Essential articles and videos from the Experts

    More valuable questions with Expert answers

    201511-LO-Qu-074

    Extend your technology team with the Experts Exchange community.

    — trusted by —

    Who answers my questions?Our community has technology experts around the world.

    Fernando Soto

    Expert in:

    • .NET Programming
    • Visual Basic.NET
    • C#
    • ASP.NET
    • Editors IDEs

    käµfm³d   👽

    9

    Articles

    Expert in:

    • .NET Programming
    • C#
    • Visual Basic.NET
    • ASP.NET
    • Regular Expressions

    Jacques Bourgeois (James Burger)

    2

    Articles

    Expert in:

    • .NET Programming
    • Visual Basic.NET
    • C#
    • MS Development
    • ASP.NET

    Alexandre Simões

    6

    Articles

    Expert in:

    • .NET Programming
    • C#
    • JavaScript
    • Visual Basic.NET
    • ASP.NET

    Lokesh B R

    Expert in:

    • .NET Programming
    • ASP.NET
    • C#
    • Visual Basic.NET

    Karrtik Iyer

    Expert in:

    • .NET Programming
    • C#
    • Visual Basic.NET
    • ASP.NET
    • C++

    Éric Moreau

    2

    Articles

    Expert in:

    • .NET Programming
    • Visual Basic.NET
    • C#
    • Visual Basic Classic
    • ASP.NET

    Gustav Brock

    9

    Articles

    Expert in:

    • MS Access
    • Query Syntax
    • Databases
    • Visual Basic Classic
    • .NET Programming

    AndyAinscow

    11

    Articles

    Expert in:

    • .NET Programming
    • C#
    • System Programming
    • Visual C++.NET
    • C++

    RELATED TOPICS view all topics

    1. ASP.NET
      (122,078)
    2. C#
      (90,380)
    3. Visual Basic.NET
      (91,427)
    4. MS Development
      (48,689)
    5. Editors IDEs
      (25,092)
    6. Visual Basic Classic
      (162,812)
    7. MS SQL Server
      (154,651)
    8. MS SQL Server 2005
      (71,588)
    9. Programming
      (51,615)
    10. JavaScript
      (117,322)