Solved

Nested datagridview

Posted on 2009-05-03
6
2,057 Views
Last Modified: 2012-05-06
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  
0
Comment
Question by:Idarac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 5

Expert Comment

by:mrcoolcoder
ID: 24292300
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">
OnRowCancelingEdit="InitiativeDetail_RowCancelingEdit"
OnRowEditing="InitiativeDetail_RowEditing"
OnRowUpdating="InitiativeDetail_RowUpdating"
OnRowDataBound="InitiativeDetail_RowDataBound"
OnRowDeleting="InitiativeDetail_RowDeleting" >
.........
<asp:Gridview>
0
 
LVL 5

Accepted Solution

by:
mrcoolcoder earned 500 total points
ID: 24292326
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")
        oList.DataBind()

    End Sub
0
 
LVL 1

Author Comment

by:Idarac
ID: 24294184
I want to do this using winforms not a web app. Will this code work  for a VB.Net windows app?
0
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!

 
LVL 5

Expert Comment

by:mrcoolcoder
ID: 24297132
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.
http://www.devexpress.com/Products/NET/Controls/WinForms/Grid/
0
 
LVL 5

Expert Comment

by:mrcoolcoder
ID: 24333138
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. :(

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_23585082.html
0
 
LVL 1

Author Closing Comment

by:Idarac
ID: 31577386
The answer gave me enough insight to help in sovling my problem
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question