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 7754523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:19:51+00:00 2026-06-01T12:19:51+00:00

I have 2 forms. in form 1, I have a treeview. in one method,

  • 0

I have 2 forms. in form 1, I have a treeview. in one method, I get list of nodes that checked.

private void CreateListOfCheckedNodes()
        {
            TreeNodeCollection nodes = TreeData.Nodes;
            Int32 EffectedNodes = GetCheckedNodesCount(nodes);
            if (EffectedNodes > 0)
            {
              ;//my code
            }
        }

        public int GetCheckedNodesCount(TreeNodeCollection nodes)
        {
            int CheckedNodesCount = 0;

            for (int i = 0; i < nodes.Count; i++)
            {
                TreeNode node = nodes[i];
                if (node.Checked)
                {
                    TreeFieldSet Item = new TreeFieldSet { TreeId = Int32.Parse(node.Tag.ToString()), Title = node.Text };
                    MyProject.Tree.TreeCheckedNodes.TreeList.Add(Item);
                    CheckedNodesCount++;
                }

                if (node.Nodes.Count > 0)
                    CheckedNodesCount += GetCheckedNodesCount(node.Nodes);
            }
            return CheckedNodesCount;
        }

How can I calling method CreateListOfCheckedNodes in Form 2 without new of Form1 ?
With this calling :

Tree.TreeSubjects Ts = new Tree.TreeSubjects();
Ts.CreateListOfCheckedNodes();//if CreateListOfCheckedNodes public

I get error !

Please Help !

  • 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-06-01T12:19:52+00:00Added an answer on June 1, 2026 at 12:19 pm

    Move the code into a new class that can be accessed by both forms.

    You can make the method static if it doesn’t use any member variables (a quick glance at the code seems to suggest that this is the case).

    static class TreeNodeCollectionHelper
    {
        public static int GetCheckedNodesCount(TreeNodeCollection nodes)
        {
            ...
        }
    }
    

    You could also consider making it an extension method of the TreeNodeCollection class, but this should be done with caution as it may surprise your colleagues.

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

Sidebar

Related Questions

I have a form MainForm which is a Windows Forms form that contains many
I have a form that looks like this: class SampleForm(forms.Form): text = forms.CharField(max_length=100) In
I have on my form a TreeView with a lots of items/nodes. When I
I have a form that has 2 splitters. One splitter splits the form horizonally
i have a treeview on a web forms application. i have javascript function that
I have a form tha contains a TreeView with many Textboxes in each node.
I have a TreeView in my form for which I dont want to have
I have a TreeView control on a form. I am dynamically adding new TreeNodes
I have a form like: #forms.py from django import forms class MyForm(forms.Form): title =
I have a form MyForm : System.Windows.Forms.Form {} and I need to call Site.GetService(..)

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.