Windows Develop Bookmark and Share   
 index > Windows Forms General > A good way to load a bunch of hardcored variables
 

A good way to load a bunch of hardcored variables

Hi, I have a list of variables with their hardcode values i want to use.

Is there a way to put them on a separate file ( XML, Text, etc ) and then load them on demand?

I have a combobox where the user selects, and i load a variable depending on that he selected.

I just dont want to load 50+ variables in my main code if it can be avoided.

Thanks!

DVAz  Monday, January 21, 2008 9:08 PM

Yes, the exact name you used to defined the variable will be part of the intellisense.

I have not tried a direct binding to Settings, but you can just always put a code in the ValueChanged(or similar event) of checkbox and radio-box to handle the assignment.

JRQ  Tuesday, January 22, 2008 4:40 PM

Using the Application Setting is the easiest way to load pre-defined values.

JRQ  Monday, January 21, 2008 10:24 PM

Could you give me an example of how i would do that?

I looked into MSDN and it shows examples with databindings, not sure if that is what i want.

Thanks!

DVAz  Monday, January 21, 2008 10:45 PM

VS2005 and VS2008: Right-click on the the project to which you wanna add the settings. This will open the project property window. Click on "Settings," this is theneweditor for the app.config. You don't have to touch app.config. If you need to getback to the grid justdouble-click on Settings.settings under the Propertynode.

You might want to set the Scope to Application instead of User.

Tobe able to access these settings, just create an instance of the Settings class;

<Your Project NameSpace>.Properties.Settings settings = new<Your Project NameSpace>.Properties.Settings();

JRQ  Monday, January 21, 2008 11:55 PM

I see.

Correct me if im wrong.

So in the grid under name thats my variable name, type is whatever i need it to be, and so on.

So when im done, i create an instance of it, then i can just reference the variables as i would normally do?

like myvar = myAppSetting.mybar1

and so on?

DVAz  Tuesday, January 22, 2008 1:13 AM
Also one more question, wonder if this is possible.

Basically i have one variable in my code that i want it assigned to whatever the user selected value is.

byte ProfileControl //My Local variable.


Lets say in my App Settings i have a field called: Voltage_Control = byte 0x20;

When user selects Voltage Control from the CHeckedListbox or RadioButtons, to automatically set the value of my variable.

Like ProfileControl = Voltage.Control

SO basically is there a way to bind each item of a the checkedlistbox to a value.?

Hope im clear. Thanks for the help btw. Smile
DVAz  Tuesday, January 22, 2008 6:35 AM

Yes, the exact name you used to defined the variable will be part of the intellisense.

I have not tried a direct binding to Settings, but you can just always put a code in the ValueChanged(or similar event) of checkbox and radio-box to handle the assignment.

JRQ  Tuesday, January 22, 2008 4:40 PM

You can use google to search for other answers

Custom Search

More Threads

• Size of the explorer window Title bar in C#
• How to detect arrow keys in vb.net?
• Scrolling Question
• ToolStrip doesn't scale buttons in the overflow menu
• Animation
• Trouble with Transparency
• Need help...
• How to pass a list[] into a listbox?
• Databound DataGridViewComboBoxCell ArgumentException
• System Tray Application Hangs When Logging Off Windows XP