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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:35:04+00:00 2026-06-16T09:35:04+00:00

Currently creating a windows form application program based on the decorator pattern in C#.

  • 0

Currently creating a windows form application program based on the decorator pattern in C#. The program is structured to have one main class (“Computer”) of which is extended to other classes(as wrappers) which form the options available.

Problem: Using a checkedboxlist where user has the choice to choose between options which makes text specific to each option appear in one label when they are checked no matter if only one(only that checked option text will be shown after the label text) or all are checked (all checked options text will be shown one after the other after the label text). Following code shows the set text for the latest option checked in the label and it does not remove the text were the user to uncheck all options.

foreach (object itemChecked in checkedListBox1.CheckedItems)
        {
            Computer computer = (Computer)itemChecked;
            label1.Text = "" + computer.description();
        } 

That problem was solved on here but the solution replaced “description” with ToString. My problem with that is, I am looking to use what is held in “description” for the text in the label rather than what is being held in ToString which is being used to name each checked option. Below are code examples of them both from the main class (Computer):

public virtual String description()
    {
        return "Currently in basket is a Computer ";
        //return this.ToString();
    }

public override string ToString()
    {
        return "Desktop";
    }

The reason behind that is to keep to the decorator pattern structure, ToString bypasses that as it can be used in the same way without the decorator pattern structure. The solution spoken of before follows:

private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
    if (e.NewValue == CheckState.Checked && e.CurrentValue == CheckState.Unchecked) //Continue if the new CheckState value of the item is changing to Checked
    {
        label1.Text += "a " + checkedListBox1.Items[e.Index].ToString() +", "; //Append ("a " + the item's value + ", ") to the label1 Text property
    }
        else if (e.NewValue == CheckState.Unchecked && e.CurrentValue == CheckState.Checked) //Continue if the new CheckState value of the item is changing to Unchecked
        {
            label1.Text =  label1.Text.Replace("a " +checkedListBox1.Items[e.Index].ToString() + ", ", ""); //Replace ("a " + the item's value + ", ") with an empty string and assign this value to the label1 Text property
        }
}

A solution, I think found on another topic(can’t remember exactly), much closer to what I am looking for, below, uses “description” for the value of the label while the ToString stays as the value for the options. However this code brings an error of there being no definition of “CheckedItem” nor any extension method by the very same name (end of the fourth line):

for (int i = 0; i < checkedListBox1.Items.Count; i++)
            if (checkedListBox1.GetItemChecked(i))
            {
                Computer computer = (Computer)checkedListBox1.CheckedItem;
                label1.Text = "" + computer.description();
            }
            else
            {
                label1.Text = "";
            }

P.S. I am a novice/beginner programmer, excuse any inconsistencies or badly explained parts. Thank you.

  • 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-16T09:35:05+00:00Added an answer on June 16, 2026 at 9:35 am

    If I well understood what you want to do, then you need to create a public function that returns Computer.ToString():

    public string Description(){
        return this.ToString();
    }
    
    protected override ToString(){
        /// and here goes the code you need.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application I have one windows form application and two windows services. Currently
I am currently developing a C# Windows Form Application. In the main form, there
I am creating a windows store application that currently loads a simple class (which
I'm creating an installer for my Windows client application. Currently I create an MSI
I am currently creating an application for compiling multiple java projects in one go
I'm currently creating a form validation script based on the jQuery validator plugin .
I am currently creating a customer application for a local company. I have a
I have a Windows form application that users can log into. The application is
I'm creating a multilingual application using Windows Forms. I have created my multilingual content
I'm creating my first Windows Forms Application, and one requirement is that there is

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.