Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I set LineStyle from a comboBox

Hi everyone,
I need a little help.
I am writing a windows form application in C# 2005, using MCC MStudio 8.0.1
 
I am writing an application which provides the user with a settings panel to set his required style settings for a waveformgraph.
An added complication is that I need to restore the last used settings each time the application is run.
 
My main problem is finding out how to convert string information into a usable form for the various waveformGraph properties.
 
As an example:
 
I have build a combobox which contains the default available LineStyles as below

foreach (LineStyle style in EnumObject.GetValues(typeof(LineStyle)))

{ cbLineStyle.Items.Add(style);}

cbLineStyle.SelectedIndex = 5;

If I select an item in the combobox I get the line style returned as a string.  This is fine to write to the registry.

My problem is how to use the string to set the LineStyle property.

1.  Can anyone help me?

2. Can anyone suggest a good reference source for MStudio.  I confess that I find the help system rather unhelpful!Smiley Sad

Many thanks

John 822179

Live long, prosper and understand Measurement Studio?

 

 

 

 

 

0 Kudos
Message 1 of 5
(4,300 Views)

Hi John,

There is a much easier solution for what you are trying to do.  We have PropertyEditor controls that allow you to edit properties of an object at run-time.  In your case, you could set the PropertyEditor control to allow you to set the LineStyle property of a WaveformPlot object at runtime.  You simply drop down the PropertyEditor control from the Toolbox, right-click the control and select Edit Source, and then choose your Object and Property Name. In this case, you would select waveformPlot1 (unless you changed the name of your plot as this is the default) for the Object and LineStyle for the Property Name.  See screenshot Property Editor Source Editor.

You would then have a nice drop-down box to select from.  See attached Example screenshot and the small example.  Use this method when trying to set properties at run-time. We also have an PropertyEditor example that you should look at under the examples <MeasurementStudioVS2005>\DotNET\Examples\UI\WindowsForms\PropertyEditor.

To address your second question, I would suggest checking out our Using Measurement Studio .NET Class Libraries topics under NI Measurement Studio Help >> NI Measurement Studio .NET Class Library >> Using the Measurement Studio .NET Class Libraries. Then check out the Using the Measurement Studio Windows Forms .NET Controls.

If you have any suggestions on how to improve our help, or areas that you see we are weak in, please let me know by submitting a product suggestion.

Best Regards,

Message Edited by Jonathan N on 07-23-2007 08:50 AM

Jonathan N.
National Instruments
0 Kudos
Message 2 of 5
(4,299 Views)
In order to convert the LineStyle string value to a corresponding LineStyle object, you will need to use EnumObject.Parse method. Since LineStyle is a derived class of EnumObject and behaves like an enumeration, you will use similar paradigms to convert a string to an object. In the case of a regular enumeration, you would have used Enum.Parse if you wanted to convert the string representation of an enumeration to an enumeration value. Similarly, for LineStyle, you will need to use the EnumObject.Parse method for performing the corresponding conversion.
 
Jonathan's suggestion still stands. The PropertyEditor control will make your life easier if you want edit propery values at run-time. If you are saving these values across application lifetimes, then you can save the values as strings in a location suitable to you (like the registry, you mentioned) and convert it back to a string when the application is launched again using the mechanism described above.
Abhishek Ghuwalewala | Measurement Studio | National Instruments
0 Kudos
Message 3 of 5
(4,290 Views)

Hi Jonathan,

Thanks for your excellent, detailed reply. 

I am sure that I will use the Property editor in the future, but for the current application, I will stick with what I am doing.

 

I will spend some time over the few days and let you have a product suggestion regarding the help system.

 

Many thanks

John 822179

Live long, propser and understand C#?

0 Kudos
Message 4 of 5
(4,277 Views)

Hi Abhishek,

Thanks for your reply.

I had found Enum.Parse, but not EnumObject.Parse.

My other problem was understanding how to use it, once I knew it existed!

Searching for EnumObject in the help system didn't help too much.  Yes, it is there, but what is there didn't prepare me for what I needed to do to use it!Smiley Wink

After searching MSDN for Enum.Parse, and doing a bit of COLUMBOing, I eventually created the following line of code:

waveformPlot1.LineStyle = (

LineStyle)EnumObject.Parse(typeof(LineStyle), Convert.ToString( cbLineStyle.SelectedItem ));

Phew, I hope that I can find this again when I need it!!Smiley Wink

Many thanks for your help,

John822179

Live long, prosper and understand Measurment studio?

 

0 Kudos
Message 5 of 5
(4,276 Views)