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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:49:54+00:00 2026-05-27T14:49:54+00:00

I may be going about this the wrong way, so I’ll set out the

  • 0

I may be going about this the wrong way, so I’ll set out the full scenario…

I have a DataTable which holds a number of items – like stock items. The data in this table can change, but it’s populated from a database so that it’s a distinct list. I want users to be able to select a number of them and I want to do this by creating a new checkBox object for each item in my DataTable.

So far I have the following (which I know is wrong, but illustrates what I’m trying to get at!):

string cbName = "cbNewTest";
int cbPosition = 24;
int cbTab = 1;

foreach (DataRow row in tblAllTests.Rows)
{
    string cbNewName = cbName + cbTab.ToString();
    this.(cbNewName) = new System.Windows.Forms.CheckBox();
    this.testInfoSplitContainer.Panel2.Controls.Add(this.(cbNewName));

    this.(cbNewName).AutoSize = true;
    this.(cbNewName).Location = new System.Drawing.Point(6, cbPosition);
    this.(cbNewName).Name = cbNewName;
    this.(cbNewName).Size = new System.Drawing.Size(15, 14);
    this.(cbNewName).TabIndex = cbTab;
    this.(cbNewName).Text = row["itemDesc"].ToString();

    cbPosition = cbPosition + 22;
    cbTab = cbTab + 1;
}

So of course the problem is the stuff in the brackets. Essentially, I want this to be whatever is in my string ‘cbNewName’ but I really don’t know how to do this…I’m used to SQL as I’m a database gal, so this probably means I’ve coded this all wrong…

Any help would be very much appreciated…I’m very new to C# (or for that matter, any programming outside a database) so simple terms would be appreciated!

  • 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-27T14:49:55+00:00Added an answer on May 27, 2026 at 2:49 pm

    You can create a CheckBox as a variable, just like anything else. No need to assign it to one of the Form‘s properties, which are impossible to generate dynamically regardless:

    CheckBox newCheckBox = new CheckBox();
    
    // (Initialize your new CheckBox here, basically exactly as you're
    // already doing except instead of this.(cbNewName) you use newCheckBox)
    
    this.testInfoSplitContainer.Panel2.Controls.Add(newCheckBox);
    

    If you need to access it later, since you’re already setting the name, just do:

    (CheckBox)this.testInfoSplitContainer.Panel2.Controls["theName"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I may be going about this the wrong way. I have a container of
I may be going about this backwards... I have a class which is like
I'm wondering if I may be going about this the wrong way and am
I'm new to Python so I may be going about this completely wrong, but
I'm probably going about this all wrong, but hey. I am rendering a large
Alright, I am going to state up front that this question may be too
This really is an architectural question. I feel like I'm going about this the
Simple question, the answer may not be... I'm going to be developing a web
may i know how to use this getMicrophone with simpleFLVWriter to create flv with
I'm trying to wrap my brain about how to do this. We need to

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.