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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:01:35+00:00 2026-06-14T12:01:35+00:00

When we press the btnSettings, all the user controls properties will be displayed in

  • 0

When we press the btnSettings, all the user controls properties will be displayed in Property grid. I want display specific properties (only TemperatureValue and TemperatureUnit), is possible? User control code as follows:

using System;
using System.Windows.Forms;

namespace Temperature
{
    public partial class temperatureUc : UserControl
    {
        public enum temperatureUnit
        {
            Celsius,    // default
            Delisle,    // °De = (100 − °C) * 3⁄2
            Fahrenheit, // °F  = °C * 9⁄5 + 32  
            Kelvin,     // °K  = °C + 273.15
            Newton,     // °N  = °C * 33⁄100
            Rankine,    // °R  = (°C + 273.15) * 9⁄5
            Réaumur,    // °Ré = °C * 4⁄5   
            Rømer       // °Rø = °C * 21⁄40 + 7.5
        }

        public temperatureUc()
        {
            InitializeComponent();
            this.cboTemperatureUnit.DataSource = Enum.GetValues(typeof(temperatureUnit));
        }

        #region "Event"
        public delegate void SettingsStateEventHandler(object sender, EventArgs e);
        public event SettingsStateEventHandler settingsStateChanged;

        private void OnSettingsChanged(object sender, EventArgs e)
        {
            if (this.settingsStateChanged != null)
                this.settingsStateChanged(sender, e);
        }
        #endregion

        #region "Properties"
        private Single _TemperatureValue;
        public Single TemperatureValue
        {
            get
            {
                return this._TemperatureValue;
            }
            set
            {
                if (value.GetType() == typeof(Single))
                {
                    _TemperatureValue = value;
                    this.txtTemperatureValue.Text = _TemperatureValue.ToString();
                }
            }
        }

        private temperatureUnit _TemperatureUnit;
        public temperatureUnit TemperatureUnit
        {
            get
            {
                return this._TemperatureUnit;
            }
            set
            {
                if (value.GetType() == typeof(temperatureUnit))
                {
                    _TemperatureUnit = value;
                    this.cboTemperatureUnit.Text = _TemperatureUnit.ToString();
                }
            }
        }
        #endregion

        private void btnSettings_Click(object sender, EventArgs e)
        {
            this.OnSettingsChanged(sender, e);
        }
    }
}

User control above code will be called from code bellow:

using System;
using System.Windows.Forms;
using Temperature;
using System.Diagnostics;
using System.Drawing;

namespace TemperatureImplements
{
    public partial class Form1 : Form
    {
        private PropertyGrid pGrid  = new PropertyGrid();  

        public Form1()
        {
            InitializeComponent();
            this.temperatureUc1.settingsStateChanged += new temperatureUc.SettingsStateEventHandler(temperatureUc1_settingsStateChanged);
        }

        void temperatureUc1_settingsStateChanged(object sender, EventArgs e)
        {
            pGrid.Size = new Size(300, 500);
            pGrid.Location = new Point(300,10);
            pGrid.SelectedObject = temperatureUc1;
            this.Controls.Add(pGrid);
        }

    }
}

Picture as follows:
Display Specific Property grid

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

    There is a way. This article has a section called “Customizing the PropertyGrid Control” that explains how to do it http://msdn.microsoft.com/en-us/library/aa302326.aspx#usingpropgrid_topic5

    Basically you just want to define the AppSettings class to only include TemperatureUnit andTemeratureValue`.

     AppSettings appset = new AppSettings();
     MyPropertyGrid.SelectedObject = appset;
    

    Define AppSettings as follows;

    [DefaultPropertyAttribute("SaveOnClose")]
    public class AppSettings{
    private bool saveOnClose = true;
    private string tempUnit;
    private int tempValue;
    
    [CategoryAttribute("Global Settings"),
    ReadOnlyAttribute(false),
    DefaultValueAttribute("Celsius")]
    public string TemperatureUnit
    {
        get { return tempUnit; }
        set { tempUnit = value; }
    }
    
    [CategoryAttribute("Global Settings"),
    ReadOnlyAttribute(false),
    DefaultValueAttribute(0)]
    public string TemperatureValue
    {
        get { return tempValue; }
        set { tempValue = value; }
    }
    }
    

    By the way, I’m changing the category from Misc to Global Settings, don’t know if that’s what you want but it makes sense when they’re the only options. You may have to explicitly declare the other attributes this BrowsableAttribute(false) so they’re not displayed but I don’t think it’s necessary.

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

Sidebar

Related Questions

when I press the Maximize button on my WPF app, all the controls therein
I want to press an Android button and automatically direct the user to the
When my user press Enter on the virtual android user validate entry! keyboard my
If you press and hold the 5 key on the numpad it will continue
When I press the button onces, I want to start count, and when I
on (press) { here I want to call a javascript function } on (rollOver)
When I press F5 in Visual Studio 2008, I want Google Chrome launched as
When I press a button, I would like to disable screen rotation on all
Is it possible to press a button in iPhone SDK programmatically without the user
For example I want press 'v' to get 'asdfv' by autohotkey, but when I

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.