?
Solved

creating a threaded datagrid

Posted on 2006-05-05
5
Medium Priority
?
262 Views
Last Modified: 2009-12-16
this is more of a conceptual question at first that will probably get to practical examples later. what i'm trying to do is very much like what you see on a message board application, where you have categories with topics underneath and threads inside each topic. i want to create a simple navigation for this that is something like a treeview, but i'd rather not create an xml file for the menu. i'm hoping there is a way to use a nested datagrid of sorts so that i can take a table with information like

ID     Name      ParentID
1       abc          0
2       def          0
3       bfr           1
4       ghy          1
5       ius           2

and turn it into

abc
 > bfr
 > ghy
def
 > ius

if this table structure is not the most efficient for what i want to do, what would be? and how would i go about making a nested datagrid of this type? if i can get to the point of the top level categories remaining in their own rows with the subcategories taking up another row, i can probably figure out a way to indent them on my own, however, i'd like it to also be collapsible, again like a treeview. if a treeview is what i should use, how do i bind it to a datatable?
0
Comment
Question by:craskin
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
TornadoV earned 2000 total points
ID: 16616307
I would use TreeView to display your content.

This is a great example of how to add treenodes to a treeveiw programmatically:

http://www.codeguru.com/csharp/.net/net_asp/controls/article.php/c11797
0
 
LVL 12

Author Comment

by:craskin
ID: 16616585
that looks great. i'll try that.
0
 
LVL 12

Author Comment

by:craskin
ID: 16619100
ok, so i've followed that example and i have

Private Sub FillCategories(ByVal parent As TreeNode)
        Dim dsCategories As DataSet = objCicada.GetCategories()
       
        For Each row As DataRow In dsCategories.Tables(0).Rows
            Dim node As New TreeNode
            node.Text = row("CategoryName").ToString
            node.Value = row("CategoryID").ToString
            node.PopulateOnDemand = True
            node.SelectAction = TreeNodeSelectAction.SelectExpand
            parent.ChildNodes.Add(node)
        Next
    End Sub
   
    Private Sub FillTopics(ByVal parent As TreeNode)
        Dim dsTopics As DataSet = objCicada.GetSubCategories(parent.Value)
       
        For Each row As DataRow In dsTopics.Tables(0).Rows
            Dim node As New TreeNode
            node.Text = row("CategoryName").ToString
            node.Value = row("CategoryID").ToString
            node.PopulateOnDemand = False
            node.SelectAction = TreeNodeSelectAction.SelectExpand
            parent.ChildNodes.Add(node)
        Next
    End Sub
   
    Protected Sub TreeView1_TreeNodePopulate(ByVal Sender As Object, ByVal e As TreeNodeEventArgs)
        Select Case e.Node.Depth
            Case 0
                FillCategories(e.Node)
            Case 1
                FillTopics(e.Node)
        End Select
           
    End Sub

and the control looks like

<asp:TreeView ID="TreeView1" OnTreeNodePopulate="TreeView1_TreeNodePopulate" runat="server"/>

but it doesn't render anything. i feel like i'm missing something from the treeview control to actuall fire it, but i dunno what that would be as i've never worked with a treeview before.
0
 
LVL 12

Author Comment

by:craskin
ID: 16619134
nevermind, i found it. it needed a node to start with, which is odd. so now it has a -1 level node with the 0 level categories underneath.
0
 
LVL 11

Expert Comment

by:TornadoV
ID: 16619348
You're right, treeview control needs a startup node, it's usually the root node.  I also found extremely useful not to populate the entire treeview, especially if you have more than two levels of hierarchial data and populate only those treenodes that user clicks on, 'just-in-time'.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

850 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