Solved

Nested datagridview

Posted on 2009-05-03
6
2,051 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now