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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:43:34+00:00 2026-05-24T18:43:34+00:00

I have a Winforms PropertyGrid in c# that controls the data that getted and

  • 0

I have a Winforms PropertyGrid in c# that controls the data that getted and setted from an embedded system.

I wrote the queries about the device (GetFrequency,SetPowerLimit,SetACCurrent e.c.) as Properties so that i can bind the data without writing another method for each command inside the Form that i want to create.

The PropertyGrid works really nice, i mean it shows all the data that i need and lets me change their values. But not always of course.

Because of this black box situtation of the device that have to work on, the program halts normally at some points. (i.e. when you turn the device off.)

For example, here is a value that i have to read frequently from the device. “Simin”

    [Category("Editable Values"), Description("Sets the minimum select...")]
    public Ampere Simin
    {
        get
        {...}
        set
        {...}
    }

Within the Getters and Setters i have these get methods that establishes the connection between pc and the device. And they are the actual source of exceptions that i take mostly.

Like this

if (!_port.IsOpen)
        {
            throw new HuettingerException(Localisation.Error_PortClosed);
        }

or this

// Read first 4 bytes
            if (_port.Read(inputv, 0, 4) != 4)
            {
                throw new HuettingerException(Localisation.Error_NoConnection);
            }

So i have three abstraction layers and i take the exceptions from the machine side (like the one shown above) while i try to read some data. I tried to catch some of them at the beginning like

 public DeviceUI()
    {
        InitializeComponent();
        try
        {                
            propertyGrid1.SelectedObject = device;
        }
        catch (TimeoutException te) // i tried other exceptions too
        {
            MessageBox.Show(te.Message);
        }

at initialization of the winform but it didn’t work.

My problem is, if it was a Button or a Textfield, i could easily catch the exceptions in the event methods, but i have no idea about handling an exception that thrown by a PropertyGrid.

Any opinions?

  • 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-24T18:43:35+00:00Added an answer on May 24, 2026 at 6:43 pm

    If the exception being thrown while converting (assigning value) (i.e. when TypeConverter.ConvertFrom() is called) to a property in the property grid (for example, InvalidCastException), then you can catch in the TypeConverter for that property.

    class MyTypeConverter : TypeConverter
    {
        public override bool ConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            try
            {
                return base.ConvertFrom(context, sourceType);
            }
            catch(Exception e)
            { 
                // Process the exception (for example, Log(e)) or Debug.Assert()
                throw;
            }
        }
    }
    
    // Using the TypeConverter in your class
    class MyClass
    {
        [ReadOnly(false)]
        [PropertyOrder(1)]
        [DisplayName("Property 1")]
        [TypeConverter(typeof(MyTypeConverter))]
        public int Property1
        {
            get;
            set;
        }
    }
    

    You can also override other methods of the base TypeConverter class accordingly.

    Going by the example, that you have added, it looks like you want the to deduce the reason why the communication with the device has failed (port not open, etc.). Then why not set a property or flag (for example, Error or CommunicationError) in the Device class that tells whether the specific error has occurred.

    Then in the TypeConverter check for this property before accessing other properties, if in error then simply return from the ConvertFrom() without calling the base implementation. If the error is recoverable, which in your case appears to be a communication error, then allow the user to retry, rather than throwing an exception.

    In addition, if you are mapping the device parameters directly onto the class and you have a property that you use in the property grid but do not want it to be written on the device, then mark it with a custom attribute (say boolean DeviceWritable). In the communication layer (where you actually write the values to the device), check for this custom attribute, if it is set as true then write to the device otherwise do not write to the device.

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

Sidebar

Related Questions

I have a winforms application that normally is at about 2-4% CPU. We are
I have C# winforms application that needs to start an external exe from time
I have a Winforms dialog that contains among other controls a TextBox that allows
I have a WinForms app that contains many NumericUpDown controls. In a nutshell, if
I have a have Winforms client that uses Web services on a IIS7 (W2008)
We have a WinForms application written in C# that uses the AxAcroPDFLib.AxAcroPDF component to
I have a winforms application that presently ships with a chm file for context-sensitive
we have WinForms app which stores data in SQL Server (2000, we are working
WinForms have those three boxes in the upper right hand corner that minimize, maximize,
I have a WinForms app. that when a button is clicked retrieves a bunch

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.