Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3348348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:31:55+00:00 2026-05-18T01:31:55+00:00

i have the below code i want to put in a global method set

  • 0

i have the below code i want to put in a global method set as static so that i can build a couple tree views on my asp.net web app. now i have each building its own tree view using the code below. i was thinking to make a global static method to generate the node structure such as this and then just assign them to the tree view in my pages… or something like this. i dotn care about the details of the actual solution as long as i can have a single method to call like “buildTree()” that will be able to be used to bind the tree view controls to.

toughs?

DataTable dtProjects = new DataTable();
            DataTable dtRelease = new DataTable();

            using (SqlConnection con = Global.GetConnection())
            {
                StringBuilder str = new StringBuilder();
                str.Append("SELECT r.ReleaseId, ");
                str.Append("       r.Name, ");
                str.Append("       rs.EndDate ");
                str.Append("  FROM Release r ");
                str.Append("  LEFT OUTER JOIN ReleaseSchedule rs ");
                str.Append("    ON r.ReleaseId = rs.ReleaseId ");
                str.Append("   AND rs.MilestoneCID = 77");
                str.Append(" WHERE r.CompletionStatusCID NOT IN (34, 35) ");
                str.Append(" ORDER BY r.ReportingPriority, r.Name ");
                SqlDataAdapter da = new SqlDataAdapter(str.ToString(), con);
                da.Fill(dtRelease);

                str = new StringBuilder();
                str.Append("SELECT p.ProjectId, ");
                str.Append("       p.ProjectName, ");
                str.Append("       p.ParentProjectId, ");
                str.Append("       p.ReleaseId ");
                str.Append("  FROM Project p ");
                str.Append(" WHERE p.CompletionStatusCID NOT IN (34, 35) ");
                str.Append("   AND p.ProjectTypeCID <> 92 ");
                str.Append(" ORDER BY p.ProjectName ");

                da = new SqlDataAdapter(str.ToString(), con);
                da.Fill(dtProjects);
            }

            tvProject.Nodes.Clear();
            TreeNode rootNode = new TreeNode("All Projects");
            rootNode.Expanded = true;

            foreach (DataRow drRelease in dtRelease.Rows)
            {
                TreeNode releaseNode = new TreeNode((string)drRelease["Name"]);
                DataRow[] releaseProjects = dtProjects.Select("(ReleaseId = " + drRelease["ReleaseId"] + ") AND (ParentProjectId IS NULL)");

                foreach (DataRow drProject in releaseProjects)
                {
                    TreeNode projectNode = new TreeNode((string)drProject["ProjectName"], drProject["ProjectId"].ToString());
                    projectNode.ToolTip = "This is a project node and is selectable";
                    loadTVNode((int)drProject["ProjectId"], projectNode, dtProjects);
                    if (drRelease["EndDate"] != System.DBNull.Value)
                    {
                        string s = ((DateTime)drRelease["EndDate"]).ToString(Global.CONST_DateFormat);
                        releaseNode.ToolTip = "Release scheduled for deployment on " + s;
                    }
                    else
                        releaseNode.ToolTip = "Release deployment has not been scheduled";

                    releaseNode.ToolTip += ". This node is not selectable";
                    releaseNode.ChildNodes.Add(projectNode);
                }
                rootNode.ChildNodes.Add(releaseNode);
            }

            tvProject.Nodes.Add(rootNode);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:31:55+00:00Added an answer on May 18, 2026 at 1:31 am

    I didn’t get the question right away, but I guess you’re looking for something like this:

    Create a class called TreeViewBuilder with just a public method to return the filled TreeView from an existing one:

    public class TreeViewBuilder
    {
        public static TreeView BuildTreeView( TreeView tree )
        {
            DataTable projects = GetProjects();
            DataTable releases = GetRealeases();
    
            return InternalTreeViewBuilder(tree, projects, releases);
        }
    }
    

    My guessing is that you can fill the blanks in this solutions, like passing those parameters you need and so on. Also you can build the code for the tree methods being called from the code you placed in the question. You creation routine would be now:

    //TreeView something;
    TreeViewBuilder.BuildTreeView(something);
    

    Even more cool, if you are using .NET framework over 3.5 you can make the method as an extension:

    public static class TreeViewBuilder
    {
        public static TreeView BuildTreeView( this TreeView tree )
        {
            DataTable projects = GetProjects();
            DataTable releases = GetRealeases();
    
            return InternalTreeViewBuilder(tree, projects, releases);
        }
    }
    

    Then, calling your method would be so much simpler:

    //TreeView something;
    something.BuildTreeView();
    

    And it’s done! MSDN has some great codes for extension methods.

    Hope I can help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table defined (see code snippet below). How can I add a
I have noticed that my geocoder is inconsistent in the code shown below because
I have a bunch of 'rowviews' that I want to put in a vertical
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD
Okay so I have a scenario similar to the below code, I have a
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
The code I have pasted below is meant to display images on the middle
So far i have got the code below which works lovely when trying an
I met an interesting issue about C#. I have code like below. List<Func<int>> actions
EDIT: See my working code in the answers below. In brief: I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.