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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:29:33+00:00 2026-05-23T21:29:33+00:00

As the topic suggests I have some problems with PropertyInfo.SetValue. To get to the

  • 0

As the topic suggests I have some problems with PropertyInfo.SetValue. To get to the point, here is my example – I have created my own class and the main thing about it is the presentation object:

using System;
using System.Reflection;

namespace TestingSetValue
{
public class Link
{
    private object presentationObject = null;
    private string captionInternal = string.Empty;

    public Link (string caption)
    {
        captionInternal = caption;
    }

    public string CaptionInternal
    {
        get { return captionInternal; }
        set { captionInternal = value; }
    }

    public bool Visible
    {
        get 
        {
            if (PresentationObject != null)
            {
                PropertyInfo pi = PresentationObject.GetType().GetProperty("Visible");

                if (pi != null)
                {
                    return Convert.ToBoolean(pi.GetValue(PresentationObject, null));
                }
            }

            return true;
        }

        set
        {
            if (PresentationObject != null)
            {
                PropertyInfo pi = PresentationObject.GetType().GetProperty("Visible");

                if (pi != null)
                {
                    pi.SetValue(PresentationObject, (bool)value, null);
                }
            }
        }
    }

    public object PresentationObject
    {
        get { return presentationObject; }
        set { presentationObject = value; }
    }

}

}

Then, I do this:

private void btnShowLink_Click(object sender, EventArgs e)
    {
        Link link = new Link("Here I am!");

        this.contextMenu.Items.Clear();
        this.contextMenu.Items.Add(link.CaptionInternal);

        link.PresentationObject = this.contextMenu.Items[0];
        link.Visible = true;

        lblCurrentVisibility.Text = link.Visible.ToString();
    }

Now, I can imagine this doesn’t look too logical/ economical, but it shows the essence of my real problem. Namely, why doesn’t the visibility of presentation object (and the value of link.Visible) change, after I call:

link.Visible = true;

I simply do not know what else to do to make this work… Any help is deeply appreciated.

To make things even more interesting, the property Enabled behaves as expected of it…

PropertyInfo pi = PresentationObject.GetType().GetProperty("Enabled");

Could it be related to the fact that Visible is actually a property of ToolStripDropDownItem base base object, whereas Enabled is ‘direct’ property of ToolStripDropDownItem ?

  • 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-23T21:29:35+00:00Added an answer on May 23, 2026 at 9:29 pm

    It would have been easier to figure this out if you said upfront what class this is but now we know it is ToolStripDropDownItem which we can infer means WinForms.

    What you are seeing is an oddity with the ToolStripItem’s Visible property. It’s setter & getter are not tied directly together. MSDN says

    “The Available property is different from the Visible property in that
    Available indicates whether the ToolStripItem is shown, while Visible
    indicates whether the ToolStripItem and its parent are shown. Setting
    either Available or Visible to true or false sets the other property
    to true or false.”

    In other words, you want to use the Available property instead of the Visible property

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

Sidebar

Related Questions

As the topic suggests I have a server and some clients. The server accepts
I have a java class Processor that is listening to a jms topic and
What is the proper way to dispose of SWT Shells? I have created some
I have a sorted mutable array of a class called Topic. The topics represent
As the topic suggests I wish to be able to pass table names as
I have been working on an iPhone project, where we created all the user
I am working on a Google app engine project where I have saved some
I have problems after upgrading: jqGrid from 3.5.3 to 3.8.2 jquery from 1.3.2 to
Googling this topic I get a sense there are three ways apple allows to
I have been querying google for some material about kd-trees and image comparison but

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.