Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle the exceptions that thrown by a propertygrid?
    primarykey
    data
    text
    <p>I have a Winforms PropertyGrid in c# that controls the data that getted and setted from an embedded system.</p> <p>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. </p> <p>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.</p> <p>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.) </p> <p>For example, here is a value that i have to read frequently from the device. "Simin"</p> <pre><code> [Category("Editable Values"), Description("Sets the minimum select...")] public Ampere Simin { get {...} set {...} } </code></pre> <p>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. </p> <p>Like this</p> <pre><code>if (!_port.IsOpen) { throw new HuettingerException(Localisation.Error_PortClosed); } </code></pre> <p>or this</p> <pre><code>// Read first 4 bytes if (_port.Read(inputv, 0, 4) != 4) { throw new HuettingerException(Localisation.Error_NoConnection); } </code></pre> <p>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</p> <pre><code> public DeviceUI() { InitializeComponent(); try { propertyGrid1.SelectedObject = device; } catch (TimeoutException te) // i tried other exceptions too { MessageBox.Show(te.Message); } </code></pre> <p>at initialization of the winform but it didn't work.</p> <p>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.</p> <p>Any opinions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload