Solved

Need help in converting VB.NET to C#

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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