Posts

Showing posts from January, 2012

Extract values from vary controls and Write it on XML

This has found in forum who shared the problem and solution as mentioned above title. Background: A form contains many controls, such as TextBox, ComboBox and etc... Then, we need to extract the value from these options. The code example is as below: foreach ( Control control in this . Controls ) {     //here 'this' is representing the form you want to iterate through     //you can check whether it is a combobox or a text box     if ( control . GetType () == typeof ( Combobox ))     {         //this is a combo box     }     else if ( control . GetType () == typeof ( Textbox ))     {         //this is a text box     } } This is a nice example as for beginner like me ^^/ Link: http://stackoverflow.com/questions/6400382/how-do-i-extract-values-from-controls-and-write-it-on-xml

Save and Read Combo Box Items from an XML File

Image
Introduction When discussing file processing, we mentioned that it is sometimes necessary to automatically save a file when an application exits, without any intervention from the user. You can also solve this exact problem using XML. The ever growing strength of XML is in its ability to let modify a file however but still make that file usable by any environment that needs its content. We are going to create an XML file that holds a list of items for a combo box. Once the file exists, it can be processed or modified by any application that can read XML. We will load the file automatically when the application opens and retrieve the values of the elements to complete a combo box . While using the application, we will allow the user to change the list. When the application closes, we will retrieve the list of items from the combo box and update (in reality) recreate the list that includes the new items. Practical Learning: Using XML Values 1. Related link:Start Visual C# and cr

How to read APP.CONFIG for user defined run-time parameters

These are the steps involved in defining runtime parameters and using them in your code. 1. Create a App.Config file 2. Define the runtime parameters and provide values for these 3. Access these parameters in your code 4. Verify changing the parameter value at runtime affects the application Step 1: Create App.Config file 1a. Create a Console Application 1b. In Solution Explorer, right click on project. Add->New Item. Select Application Configuration file. This file will be added to your project. Step 2: Define the runtime parameters and provide values for these 2a. Open App.Config. 2b. Define the keys and values for your runtime parameters. Example: You can define any key and provide values. Ensure you don’t have duplicate keys. Step 3: Access these parameters in your code 3a. Add a refernce System.Configuration DLL. 1 3b. Add the following lines in your code. You can directly add these lines in Main. Example: string name = System.Configuration.Conf