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

  • SEARCH
  • Home
  • 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 7555613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:39:17+00:00 2026-05-30T11:39:17+00:00

I have this Checked List Box, listPlayers . I would like to have it

  • 0

I have this Checked List Box, listPlayers. I would like to have it add (or remove) names when asked. These names are in string input, naturally.

Here is the code in question:

namespace TakoBot
{
    static class Program
    {
        public static Form1 MainForm { get; private set; }
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainForm = new Form1();
            Application.Run(new Form1());
        }
        public static void OnMessage(object sender, PlayerIOClient.Message m)
        {
            if (m.Type == "add")
            {
                NamesInt[m.GetString(1)] = m.GetInt(0);
                NamesString[m.GetInt(0)] = m.GetString(1);
                Program.MainForm.listPlayers.Add("PlayersName");
            }
        }
    }
}

Upon calling the action Form1.listPlayers.Add("PlayersName");, we get the error:

"'MyProgram.Form1.listPlayers' is inaccessible due to its protection level"

..Okay, my error-handling skills aren’t the best. Like I said, everything is public.

If I’m using entirely wrong actions, don’t hesitate to show me correct ones.

  • 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-30T11:39:18+00:00Added an answer on May 30, 2026 at 11:39 am

    Form1 is a type, not an instance.

    In your Program do something like this

    static class Program
    {
        public static Form1 MainForm { get; private set; }
    
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
    
            MainForm = new Form1();
            Application.Run(MainForm);
        }
    }
    

    Now you can reference the form like this (listPlayers must be public)

    Program.MainForm.listPlayers.Add("PlayersName");
    

    As an alternative, you could expose the player list as a static property in Form1

    public partial class Form1 : Form
    {
        public static CheckedListBox PlayerList { get; private set; }
    
        public Form1()
        {
            InitializeComponent();
            PlayerList = listPlayers;
        }
    
        ...
    }
    

    Now you can access it like

    Form1.PlayerList.Add("PlayersName");
    

    because it is static, i.e. PlayerList belongs to the type (class) Form1, not to an instance (object) of Form1. This works only if you have only one instance of Form1 open at any time.


    Given

    class MyClass
    {
        public static string S;
        public string I;
    }
    

    You can do this

    MyClass a = new MyClass();
    MyClass b = new MyClass();
    
    a.I = "Hello";
    MyClass.S = "One";
    
    b.I = "World";
    MyClass.S = "Two";
    

    The static variable MyClass.S can have only one value at a given time. It will be "Two" at the end of this code.

    The instance variable I can have a different value in each instance (a, b). At the end of this code a.I will be "Hello" and b.I will be "World".

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

Sidebar

Related Questions

If I have Checked list box in Win forms which I fill like this
I would like to loop through a checked list box and see which values
I have a check box in WinForms, when checked I would like it to
I have this line of code for page load: if ($(input).is(':checked')) { and it
I have this js code: $(#startSearch).live(click, function(event) { $(input:checkbox[name='searchId']:checked).each(function() { var searchId = $(this).val();
$('input[type=checkbox]').unbind().click(function(e){ $(this).attr('checked', true) return false; }); I NEED to return false because I have
I have this piece of Javascript and it just won't work. I allready checked
I have the following code: function toggleChecked(status) { $(.checkbox).each( function() { $(this).attr(checked,status); }) }
I have a 2884765579 bytes file. This is double checked with this function, that
This is my current scenario: I have checked in my grails app code +

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.