• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2074
  • Last Modified:

Nested datagridview

I am trying find a way to nest a datagridview inside a datagridview.

I have a SQL Server 2005 database. The first table is a list of folders has a FolderID field and the second tables has records which is a list of files in each folder. In the secodn tbale each record wil lhave the FolderID link to the first table.

I want to build a nest datagridview in VB.Net 2008 which will nest the records of the second table in a datagridview inside of a row of a master datagridview which contains r3ecords from the first table.

Basically I am looking for any exmaples on how to do a datagridview nested inside a datagridview  
  • 4
  • 2
1 Solution
You can do this, but keep in mind that you are doing to have to do custom coding.  

If you want to do inline editing, You will have to implement all databound events like the following.
<asp:Gridview runat="server">
OnRowDeleting="InitiativeDetail_RowDeleting" >
The key is to programatically bind the nested Gridview controls one by one. Like with the following two functions.

    Protected Sub GoalsList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles GoalsList.ItemDataBound
        If chkExpanded.Checked Then
            If e.Item.ItemType = ListItemType.Item Or _
                e.Item.ItemType = ListItemType.AlternatingItem Then

                Dim lblgoalid As Label = CType(e.Item.FindControl("GoalId"), Label)
                Dim dl As DataList = CType(e.Item.FindControl("Objectives"), DataList)
                Dim oButton As ImageButton = CType(e.Item.FindControl("ExpandButton"), ImageButton)

                oButton.ImageUrl = "images/collapse.jpg"
                BindData(dl, lblgoalid.Text)
                dl.Visible = True
            End If
        End If
    End Sub
    Private Sub BindData(ByRef oList As DataList, ByVal goalId As String)

        Dim oConn As New SqlConnection(ConfigurationManager.ConnectionStrings("objectiveConnStr").ToString())
        Dim sSql As String = "SELECT * ..."

        Dim oData As New DataSet()
        Dim oAdpt As New SqlDataAdapter(sSql, oConn)
        oAdpt.Fill(oData, "Objectives")

        oList.DataSource = oData.Tables("Objectives")

    End Sub
IdaracAuthor Commented:
I want to do this using winforms not a web app. Will this code work  for a VB.Net windows app?
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

I know this can be done with the Datagrid, because I've seen it done.  I could fish for some code, but a really nice Grid that my dev shop purchased is here.
I know I've seen some code samples but apparently I can't find them now and I am not the only one.  I guess you will have to pay some mula. :(

IdaracAuthor Commented:
The answer gave me enough insight to help in sovling my problem

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now