Solved

Need help in converting VB.NET to C#

Posted on 2006-11-27
3
222 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Device Location 4 30
2 questions 10 25
Can I command line build a C# application? 6 33
c# - Best approach for objects in functions 3 17
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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