Solved

Need help in converting VB.NET to C#

Posted on 2006-11-27
3
221 Views
Last Modified: 2012-05-05
Can someone please help me convert this VB.NET to C#

Thanks

            Dim a As Integer
            With dsTree.Tables(0)
                For a = 0 To .Rows.Count - 1
                    If .Rows(a).Item("MNU_ParentNodeID") = 0 Then
                        Dim tn As New TreeNode(.Rows(a).Item("MNU_DisplayName"), .Rows(a).Item("MNU_ID").ToString, "", .Rows(a).Item("MNU_URL"), "")
                        RecursivelyAddToNode(tn, .Rows(a).Item("MNU_ID"))
                        TreeView1.Nodes.Add(tn)

                    End If
                Next
            End With





Private Sub RecursivelyAddToNode(ByVal mymenuitem As TreeNode, ByVal ParentID As Integer)

        Dim dv As New DataView(dsTree.Tables(0))
        dv.RowFilter = ("MNU_ParentNodeID=" & ParentID.ToString)
        Dim r As DataRowView
        For Each r In dv
            Dim tn As New TreeNode(r.Item("MNU_DisplayName"), r.Item("MNU_ID").ToString, "", r.Item("MNU_URL"), "")
            mymenuitem.ChildNodes.Add(tn)
            RecursivelyAddToNode(tn, r.Item("MNU_ID"))
        Next

    End Sub




Many thanks
0
Comment
Question by:mousemat24
  • 2
3 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 18020697
First bit is something like this :

foreach (dataRow row in dsTree.Tables[0].Rows){
    if ((int)row["MNU_ParentNodeID"] == 0){
        TreeNode node = new TreeNode(row["MNU_DisplayName"].ToString(), row["MNU_ID"].ToString(), row["MNU_URL"].ToString(), "");
        RecursivelyAddToNode(node, row[MNU_ID])
        TreeView1.Nodes.Add(node)

    }
}
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
ID: 18020737
foreach (dataRow row in dsTree.Tables[0].Rows){
    if ((int)row["MNU_ParentNodeID"] == 0){
        TreeNode node = new TreeNode(row["MNU_DisplayName"].ToString(), row["MNU_ID"].ToString(), row["MNU_URL"].ToString(), "");
        RecursivelyAddToNode(node, (int)row[MNU_ID]);
        TreeView1.Nodes.Add(node);
    }
}



private void RecursivelyAddToNode(TreeNode mymenuitem, int ParentID)

        DataView dv  = new DataView(dsTree.Tables[0]);
        dv.RowFilter = ("MNU_ParentNodeID=" + ParentID.ToString());
        foreach (DataRowView r in dv){
            TreeNode tn = new TreeNode(r["MNU_DisplayName"].ToString(), r["MNU_ID"].ToString, "", r["MNU_URL"], "");
            mymenuitem.ChildNodes.Add(tn);
            RecursivelyAddToNode(tn, (int)r["MNU_ID"]);
        }
}
0
 

Author Comment

by:mousemat24
ID: 18020802
Thanks ozymandias !!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

862 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

30 Experts available now in Live!

Get 1:1 Help Now