How do I edit tabular data/data in a DataGridView in a details form?

This sample shows how to edit data from a DataGridView in a details form which opens when one double clicks on the RowHeader of the DataGridView. Since both forms are bound to the same datasource one sees an instant update on both forms when the user decides to save the data and additional roundtrips to the database are avoided. It also provides a brief introduction to DataBinding in .NET.

Source Code
Visual Basic | C#

Additional Resources
Connecting to Data in Visual Studio
Getting Started with Data Access
Windows Forms Data Binding
Forms over Data Video Series

The examples were created using Visual Basic 2008 Express (free download)/Visual C# 2008 Express (free download) but do also apply to earlier versions of Visual Studio (with minor modifications).



Comments (7)
  1. Peter says:

    It is look very stupid to create edit form static – I have many grid views bind to different tables.

    Is it possible to provide a sample code how to create controls on edit form dynamically based on the number of columns and they types?

  2. lohani says:

    Sorry,I got nothing, though this is very use ful for me in my VB-6 application to keep record of my class students and to edit on screen there Marks or Roll NO etc

  3. lohani says:


    I have made an application in VB-6 to keep recodr of my class students using MSFlexigrid which do not allow me to edit so your this example is very useful but as I am beginer in VB therefore I could not get anythig from here.

    I downloaded zip file but I cant open files inside it.

    can I get help on this score?

    With Thanks

  4. @Peter >> I can post a bit of code when I find the time. Basically what you’d have to do is to walk over the datatable in the code of the details form, add the controls dynamically to the form and bind them to the datasource. Does this help?

    @lohani >> I just downloaded the source code again and it worked for me. Which problems do you have exactly?

  5. lexxkrt says:

    If I change the value, but don’t click save,just close the window. The values in the Binding changed.

  6. Peter says:

    Yes, Daniel.

    I succeeded to create dynamically the edit form – it was little tricky with Image fields and  Form size – should recalculate form layout.

    If you want I will provide a source code (C# 2.0)?

  7. @Peter: Sure, thanks for the offer! Glad you made it! If you want I can upload your source code to”> and give you credit or you could upload it to yourself and I reference it from there. Whatever you prefer is fine with me!

    @lexxkrt: You’re right. I’ll update the code when I find a bit of time. Sorry for the inconvenience!

Comments are closed.

Skip to main content