Set RadioGroup DevExpress Winform of the items loaded from a configuration file

Scenes

DevExpress of RadioGroup option if the items are not sure, it needs to be loaded from the configuration file.

achieve

New Config folder under the project directory, the new xml configuration files in the folder.

<? XML Version = " 1.0 " encoding = " UTF-. 8 " ?> 
<-! - X-axis function Items Options Dialog configuration options in the pattern of RadioGroup> 
<items> 
    <Item> current </ Item> 
    < item> voltage </ item> 
    <item> temperature </ item> 
    <item> specific capacity </ item> 
    <item> energy </ item> 
    <item> specific energy </ item> 
    <item> AC resistance </ item > 
    <Item> power </ Item> 
    <Item> dQ / dV </ Item> 
    <Item> dQm / dV </ Item> 
</ items>

 

And set its Copy to Output Directory is newer in:

 

 

Then displays the form load event RadioGroup's.

 List<string> XradioGrupItems = initRadioGroupItem(Global.RADIO_GROUP_ITEM_FILEPATH_X);c

Read the item option in the configuration file.

 public List<string> initRadioGroupItem(string xmlFilePath)
        {
           List<string> radioGrupItems =  ChartOptionHelper.getRadioGroupItems(xmlFilePath);
           return radioGrupItems;
        }

 

Here called tools to access the profile item and saved them to a list.

 public static List<string> getRadioGroupItems(string xmlFilePath)
        {
            List<string> radioGroupItems = new List<string>();
            XmlDocument xml = ReadXMLConfigHelper.readXml(xmlFilePath);
            XmlNodeList nodeList = ReadXMLConfigHelper.getNodeListByXpath(xml, Global.RADIO_GROUP_ITEM_XPATH);
            foreach(XmlNode xmlNode in nodeList)
             {
                 radioGroupItems.Add(xmlNode.InnerText);
             }
            return radioGroupItems;
        }

 

Business tools which in turn calls the tools common to read the configuration file.

Reference tools Method:

C # Xml configuration file read and write tools commonly used methods:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100879220

Xpath expression of the above parameters global variables as global variables:

public const string RADIO_GROUP_ITEM_XPATH = "items/item";

 

Generate and assign it a value RadioGroup

 

RadioGroupX = RadioGroup new new RadioGroup ();
             the foreach ( String S in XradioGrupItems) 
            { 
                // each button corresponding to the option unit Item 
                RadioGroupItem Item = new new RadioGroupItem ();
                 // Set the value of the option value 
                item.Value = S;
                 // Set description of the value of the option values to be displayed i.e. 
                item.description = S;
                 // enable option is enabled 
                item.Enabled = to true ;
                 // add the option to the Items radiogroup
                radioGroupX.Properties.Items.Add (Item); 
            } 
            // set the default value selected 
            radioGroupX.EditValue = xAttribute.Title;
             // set the width 
            radioGroupX.Width = Global.CHART_OPTION_WIDTH;
             // add 1 remains highly consistent with the Y-axis 
            radioGroupX. * = Global.RADIO_HEIGHT the Height (XradioGrupItems.Count + . 1 );
             // set position 
            radioGroupX.Location = new new Point (Global.NOGROUP_HORIZONTAL_DISTANCE, Global.GROUP_VERTICAL_DISTANCE);
             // name 
            radioGroupX.Name = " radioGroupX ";
             // Sets the parent container 
            radioGroupX.Parent = panelControlX;

 

Guess you like

Origin www.cnblogs.com/badaoliumangqizhi/p/11526410.html