Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hallo,
I have 12 cells and two modes.

For example:
C#
if (comboBox5.SelectedItem == "Cell_1" && comboBox4.SelectedItem == "Mode_1")
    {
                xmlWriter.WriteStartElement("Cell_1");
                xmlWriter.WriteStartElement("Amplitude");
                xmlWriter.WriteString(textBox17.Text);
                //xmlWriter.WriteString(textBox7.Text);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("Frequency");
                xmlWriter.WriteString(textBox18.Text);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("Duration");
                xmlWriter.WriteString(textBox19.Text);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteEndElement(); //::::::::::::::

            }

            else if (comboBox4.SelectedItem == "Mode_2")

            {
                xmlWriter.WriteStartElement("Amplitude");
                xmlWriter.WriteString(textBox17.Text);
                xmlWriter.WriteEndElement();

               
                xmlWriter.WriteStartElement("Duration");
                xmlWriter.WriteString(textBox18.Text);
                xmlWriter.WriteEndElement();
            }
I have to check for 12 cells it should change only if i select Mode_2 in my combobox4.

Like
cell_1, mode_1:
cell_2,mode_2 :
or random cell_2,mode_2.... %%when i select mode 2: second operation has to perform with amplitude and duration...


PLease help with the code..

Thank you.

What I have tried:

tried using if statement it will be very long code if i check for all 12:2 cases.
Posted
Updated 9-Jun-17 7:04am
v2

1 solution

It will take some study, but this kind of thing can be done also using serialization.
This way you can work with a class which makes coding a lot easier, and serialize the class or List<> to XML.
See: [How to serialize an object to XML by using Visual C#]

An example using a List<>:
C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
					
public class Program
{
	public static void Main()
	{
		// Test list with classes.
		List<classElement1> listStr = new List<classElement1>();
		listStr.Add(new classElement1() { Check = true, Group = "GroupOne" });
		listStr.Add(new classElement1() { Check = false, Group = "GroupTwo" });
		
		var x = new XmlSerializer(listStr.GetType());
		x.Serialize(Console.Out, listStr);
		
		using (var strWriter = new StringWriter())
		{
			x.Serialize(strWriter, listStr);
			File.WriteAllText("test.xml", strWriter.ToString());
		}
		
		Debug.Print("Test Serialization done !");
	}

	public class classElement1
	{
		public bool Check;
		public string Group = "no group";
		public string Key = "no key";
		public string Value { get; set; }
	}

}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900