Solved

Nested datagridview

Posted on 2009-05-03
6
2,053 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 32
Crystal reports vb.net 2 39
Help with adding DLL file in Windows project 20 28
No Data for DropDown List 2 22
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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