How to Create Master/Detail Windows Forms

On my last tutorial I discuss on “How to Display Data in Windows Forms”. This time I will teach you on “How to Create Master/Detail Windows Forms”.

Creating a master/detail form still requires the same method as displaying data in windows forms. Except that we use additional control called “DataGridView”. This control will display the related record known as child form.

In our database example the Borrow and Return table is the master form and the Borrow Details and Return Details is the Detail form.

The same process as you did in our previous example we will drag the Borrow table from the Data Sources to your windows form. Before you continue on this tutorial make sure that you follow the steps on how to create a database relationship.

Now, let us add another form called “frmBorrow”. For more info please read: How to Add Windows Forms.

After you add the form drag the Borrow table from the data sources. For more info please read How to Display Data in Windows Forms on our previous tutorial.

Make sure you choose the “Details” view of Borrow table.

Next is to drag the Borrow Details UNDER the Borrow node. This is very important to the relationship of Borrow and Borrow Details form.

Borrow and Borrow Details form

As you can see in the screenshot above, there are two BorrowDetails node. Do not select the BorrowDetails which is in line with Borrow node.

Configure DataGridView control

  1. Right click on the DataGridView control. The select edit columns.

    DataGridView Edit Columns

  2. Remove BorrowDetailID and BorrowID. You do not need this anymore.

    DataGridViewComboBoxColumn

  3. Set the DataSource, DisplayMember and ValueMember.

    Select data source

    Data Properties

  4. Change the header of “BookID” to Title.

    HeaderText

You may also wish to change the width of the column.

Here’s the screenshot of our Borrow master/detail form.

frmBorrow

Now repeat this step for the Return master/detail form.

Our next topic is to add a main form so we can open all the form that we have added to our project.

Back to Visual Basic .NET 2008 Tutorial.

Comments

Submitted byAnonymous (not verified)on Wed, 01/19/2011 - 09:43

very nice tutorial
Submitted byAnonymous (not verified)on Tue, 09/25/2012 - 00:32

this is the best site for .net studio programmer

Add new comment