[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2072
  • 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?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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